我正在自动化python类的标记过程。但是,当我在线下载提交的文件时,它们包含了学生可能无意中提交了解决方案的html标记,例如:
<!DOCTYPE html><html><head><meta charset="UTF-8"></head><body><p><span style="font-family:'courier new', courier, monospace;">print("Bob and Bill Tiling Solutions Inc.")</span></p>
<p><span style="font-family:'courier new', courier, monospace;">h=int(input("Height (m):"))</span></p>
<p><span style="font-family:'courier new', courier, monospace;">w=int(input("Width (m):"))</span></p>
<p><span style="font-family:'courier new', courier, monospace;">p=int(input("Cost ($/m^2):"))</span></p>
<p><span style="font-family:'courier new', courier, monospace;">print("The total cost for this job: $" + str(h*w*p+20))</span></p>
<p> </p></body></html>我是否可以批量删除标记,这样剩下的就是:
print("Bob and Bill Tiling Solutions Inc.")
h=int(input("Height (m):"))
w=int(input("Width (m):"))
p=int(input("Cost ($/m^2):"))
print("The total cost for this job: $" + str(h*w*p+20))如果有第三方实用程序这样做,我会很高兴下载它。
我尝试通过findstr使用正则表达式,但没有效果(我的搜索字符串是"<[^>]*>",但我不知道如何使用findstr删除文本文件中的所有结果)
欢迎任何建议。
发布于 2015-03-15 04:46:31
下面是一个SED脚本(我使用GNUSED),它是我从Eric的SED一行程序中改编的:
集束线
sed -f dehtml.sed yourfilename文件dehtml.sed
:a
s/<[^>]*>//g;/</N;//bahttps://stackoverflow.com/questions/29056666
复制相似问题