擅长:python、mysql、java
<p><code>lxml</code>有一个容忍的HTML解析器。您不需要bsoup(它现在已经被作者弃用),并且应该避免使用regex来解析HTML。在</p>
<p>以下是您要寻找的第一个粗略的概述:</p>
<pre><code>guff = """\
<HTML>
<HEAD><TITLE></TITLE></HEAD>
[snip]
</DIV></BODY></HTML>
"""
from lxml.html import fromstring
doc = fromstring(guff)
for td_el in doc.iter('td'):
font_els = list(td_el.iter('font'))
if not font_els: continue
print
for el in font_els:
print (el.text, el.attrib)
</code></pre>
<p>这会产生:</p>
^{pr2}$