[英]xml file parsing in python
xml文件:
<global>
<rtmp>
<fcsapp>
<password>
<key>hello123</key>
<key>check123</key>
</password>
</fcsapp>
</rtmp>
</global>
python code:獲取所有關鍵標簽值。 你好123
using xml.etree.ElementTree
for streams in xmlRoot.iter('global'):
xpath = "/rtmp/fcsapp/password"
tag = "key"
for child in streams.findall(xpath):
resultlist.append(child.find(tag).text)
print resultlist
獲得的輸出是[hello123]
,但我希望它同時顯示兩個( [hello123, check123]
)
我如何獲得這個?
嘗試beautifulsoup包“ https://pypi.python.org/pypi/BeautifulSoup ”
使用xml.etree.ElementTree
for streams in xmlRoot.iter('global'):
xpath = "/rtmp/fcsapp/password"
tag = "key"
for child in streams.iter(tag):
resultlist.append(child.text)
print resultlist
必須遍歷for循環中的“ key”標簽以獲得所需的結果。 上面的代碼解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.