开发者

Accessing child nodein an xml in python

开发者 https://www.devze.com 2022-12-21 18:47 出处:网络
How to retrieve the value开发者_Go百科 of type in the below XML <info><category>Flip</category><info>2</info><type>Tree</type></info>

How to retrieve the value开发者_Go百科 of type in the below XML

 <info><category>Flip</category><info>2</info><type>Tree</type></info>


Using ElementTree:

import xml.etree.ElementTree as E
e = E.parse("test.xml")
print(e.find("type").text)

Using minidom:

import xml.dom.minidom
d = xml.dom.minidom.parse("test.xml")
print(d.getElementsByTagName("type")[0].firstChild.data)

Using BeautifulSoup:

from BeautifulSoup import BeautifulStoneSoup
soup = BeautifulStoneSoup(open("test.xml"))
print(soup.find("type").text)
0

精彩评论

暂无评论...
验证码 换一张
取 消