方法解析多个.html文件并删除部分html代码



解析目录内的多个.html文件,搜索和删除这些文件中的部分HTML代码的正确方法是什么?例如,我需要从所有文件中删除一个html代码:

<div class="box">
<h2>Book Search</h2>
<div id="search">
<form action="http://www.biology35.com/search.php" method="post">
<input type="text" name="searchfor" class="txtField" />
<input type="image" src="new/images/btn-go.png" name="Submit" value="Submit" class="button" />
<div class="clear"><!-- --></div>
</form>
</div>
</div>

我在Debian上使用Geany 1.29文件编辑器。Regex可能不适合这个。一些shell脚本或python?

你可以使用html,例如:

html = """
something before
<div class="box">
<h2>Book Search</h2>
<div id="search">
<form action="http://www.biology35.com/search.php" method="post">
<input type="text" name="searchfor" class="txtField" />
<input type="image" src="new/images/btn-go.png" name="Submit" value="Submit" class="button" />
<div class="clear"><!-- --></div>
</form>
</div>
</div>
html after
"""
import htql
x=htql.query(html, "<div norecur (class='box') > &delete ")[0][0]

你:

>>> x
'nsomething beforen    nnhtml aftern'

最新更新