我已經使用的urllib得到以下數據:Python和XML處理
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<videos xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:www="http://www.www.com"">
<video type="cl">
<cd>
<src lang="music">http://www.google.com/ </src>
</cd>
</video>
</videos>
我想http://www.google.com/
出去,這裏是我的代碼:
import xml.etree.ElementTree as etree
data='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><videos xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:www="http://www.www.com""><video type="cl"><cd><src lang="music">http://www.google.com/ </src></cd></video></videos>'
tree = etree.fromstring(data)
geturl=tree.findtext('/video/cd/src').strip()
print geturl
我得到錯誤:
AttributeError: 'NoneType' object has no attribute 'strip'
顯然,findtext
失敗。我試過findtext('src')
,也不會工作。
怎麼了?
錯誤的回溯是什麼?此外,運行此代碼不會產生相同的錯誤。 –