我通过网络获取的 xml 代码如下所示
<?xml version='1.0' ?><liverequestresponse><liverequesttime>180</liverequesttime><livemessage></livemessage></liverequestresponse>
我的 python minidom 代码是
import urllib, urllib2, time
from xml.dom.minidom import parse
response = urllib2.urlopen(req)
the_page = response.read()
#print the_page
dom = parse(response)
name = dom.getElementsByTagNameNS('liverequestresponse')
print name[0].nodeValue
给出了一些错误
print the_page
工作正常
或者,如果它们是比 minidom 更好的任何其他库,请告诉我.. 我更喜欢预装在 linux 上的库
更新
错误
Traceback (most recent call last):
File "logout.py", line 18, in <module>
dom = parse(response)
File "/usr/lib64/python2.7/xml/dom/minidom.py", line 1920, in parse
return expatbuilder.parse(file)
File "/usr/lib64/python2.7/xml/dom/expatbuilder.py", line 928, in parse
result = builder.parseFile(file)
File "/usr/lib64/python2.7/xml/dom/expatbuilder.py", line 211, in parseFile
parser.Parse("", True)
xml.parsers.expat.ExpatError: no element found: line 1, column 0