<p>另外请看一下<a href="http://pythonhosted.org/pyquery/" rel="nofollow">PyQuery</a>,我喜欢jQuery提供的熟悉性:</p>
<pre><code>>>> from pyquery import PyQuery as pq
>>> html = '''<table id="test_table">
... <td>
... <a href="#">#</a>
... <a href="#">#</a>
... <a href="#">#</a>
... <a href="#">#</a>
... <a href="#">#</a>
... <a href="#">#</a>
... <a href="#">#</a>
... <a href="#">#</a>
... </td>
... </table>
... <table id="test_table2">
... <td>
... <a href="#">#33</a>
... <a href="#">#33</a>
... <a href="#">#33</a>
... <a href="#">#33</a>
... <a href="#">#33</a>
... <a href="#">#33</a>
... <a href="#">#33</a>
... <a href="#">#33</a>
... </td>
... </table>'''
>>> d = pq(html)
>>> for a in d('#test_table').find('a'):
... print a.attrib.items()
...
...
[('href', '#')]
[('href', '#')]
[('href', '#')]
[('href', '#')]
[('href', '#')]
[('href', '#')]
[('href', '#')]
[('href', '#')]
</code></pre>