[英]while parsing xml getting none type even it has some value,how can i solve this issue?
輸入
如您所見,我正在嘗試解析的 xml 代碼具有名稱價值,那么它怎么可能是 NoneType?
import xml.etree.ElementTree as ET
input='''
<stuff>
<user>
<user x='2' >
<id>001</id>
<name>chuck</name>
</user>
<user x ='7'>
<id>009</id>
<name>brent</name>
</user>
</user>
</stuff>
'''
stuff=ET.fromstring(input)
print(stuff.find('name').text)
output
AttributeError Traceback (most recent call last)
<ipython-input-7-f10e349a116e> in <module>
16 '''
17 stuff=ET.fromstring(input)
---> 18 print(stuff.find('name').text)
AttributeError: 'NoneType' object has no attribute 'text'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.