我正在为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
删除文本文件中的所有结果)
欢迎任何建议。
答案 0 :(得分:1)
这是一个SED
脚本(我使用GNUSED),我改编自Eric Pement的SED One-liners:
sed line
sed -f dehtml.sed yourfilename
文件 dehtml.sed
:a
s/<[^>]*>//g;/</N;//ba