我试图从中提取作者:
<icon>
<tags>
<tag>steam</tag>
</tags>
<author>Author Name</author>
<authorwebsite>http://www.domain.com/</authorwebsite>
<license>
Creative Commons (Attribution-Noncommercial-Share Alike 3.0 Unported)
</license>
<licensewebsite>http://creativecommons.org/licenses/by-nc-sa/3.0/</licensewebsite>
<iconset>Name</iconset>
<iconsetid>slug</iconsetid>
<attribution/>
<additionalsizes>
<icon>
<id>99633</id>
<size>128</size>
<tags/>
<image>
http://url1
</image>
</icon>
<icon>
<id>99633</id>
<size>256</size>
<tags/>
<image>
http://url2
</image>
</icon>
<icon>
<id>99633</id>
<size>512</size>
<tags/>
<image>
http://url3
</image>
</icon>
</additionalsizes>
</icon>
我试过了:
name = dom.getElementsByTagName('author')
print name[0].firstChild.nodeValue
AttributeError:“NoneType”对象没有属性“nodeValue”
和:
name = dom.getElementsByTagName('author')
print " ".join(t.nodeValue for t in name[0].childNodes if t.nodeType == t.TEXT_NODE)
返回空字符串。
怎么了?谢谢。