1
如何檢索類型的值在下面的XML訪問孩子nodein一個xml在Python
<info><category>Flip</category><info>2</info><type>Tree</type></info>
如何檢索類型的值在下面的XML訪問孩子nodein一個xml在Python
<info><category>Flip</category><info>2</info><type>Tree</type></info>
使用ElementTree的:
import xml.etree.ElementTree as E
e = E.parse("test.xml")
print(e.find("type").text)
使用minidom命名:
import xml.dom.minidom
d = xml.dom.minidom.parse("test.xml")
print(d.getElementsByTagName("type")[0].firstChild.data)
使用BeautifulSoup :
from BeautifulSoup import BeautifulStoneSoup
soup = BeautifulStoneSoup(open("test.xml"))
print(soup.find("type").text)