我的XML代碼的網絡弄來了看起來像這樣XML在python解析
<?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命名更好的庫,PLZ告訴我.. 我寧願它是預安裝在Linux
UPDATE
錯誤
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
...並且錯誤是? – Hamish
更新PLZ檢查 – pahnin