擅长:python、mysql、java
<p>你得到一个<code>AttributeError</code>,因为<a href="http://bazaar.launchpad.net/~leonardr/beautifulsoup/3.0/view/head:/BeautifulSoup.py#L601" rel="nofollow">BSS returns ^{<cd2>}s</a>当你循环<code>Tag</code>实例时。也许你想试试:</p>
<pre><code>soup.a.b.c.findChildren()
#[<d attr="x">
#<e>
#</e>
#<name>
#</name>
#</d>, <e>
#</e>, <name>
#</name>]
</code></pre>
<p>关于问题w/<code>name</code>:它是<a href="http://bazaar.launchpad.net/~leonardr/beautifulsoup/3.0/view/head:/BeautifulSoup.py#L531" rel="nofollow">specified as an attribute</a>,但是您可以改为:</p>
<pre><code>soup.a.b.c.d.findChildren('name')
#[<name>
#</name>]
</code></pre>
<p>设置参考代码:</p>
<pre><code>from BeautifulSoup import BeautifulStoneSoup as bss
soup = bss(markup)
</code></pre>