python dom 解析 webservice xml
__author__ = ‘yunzhongtian‘
import urllib
import xml.dom.minidom
def Nodedata(xmldoc,abtr):
name = xmldoc.getElementsByTagName( abtr )
print name
for Node in name:
for textNode in Node.childNodes:
ns= textNode.data
print ns
if ‘__main__‘==__name__:
__url=‘http://webservice.webxml.com.cn/webservices/DomesticAirline.asmx/getDomesticAirlinesTime‘
data=urllib.urlencode({‘startCity‘:‘北京‘,‘lastCity‘:‘上海‘,‘theDate‘:‘‘,‘userID‘:‘‘})
xml1=urllib.urlopen(__url,data)
DOMTree = xml.dom.minidom.parse(xml1)
#collection = DOMTree.documentElement
AirlinesTime = DOMTree.getElementsByTagName("AirlinesTime")
allData=[]
AirData={}
for node in AirlinesTime:
AirData[‘company‘]=node.getElementsByTagName(‘Company‘)[0].childNodes[0].data
AirData[‘airlineCode‘]=node.getElementsByTagName(‘AirlineCode‘)[0].childNodes[0].data
AirData[‘startDrome‘]=node.getElementsByTagName(‘StartDrome‘)[0].childNodes[0].data
AirData[‘arriveDrome‘]=node.getElementsByTagName(‘ArriveDrome‘)[0].childNodes[0].data
AirData[‘startTime‘]=node.getElementsByTagName(‘StartTime‘)[0].childNodes[0].data
AirData[‘arriveTime‘]=node.getElementsByTagName(‘ArriveTime‘)[0].childNodes[0].data
AirData[‘mode‘] =node.getElementsByTagName(‘Mode‘)[0].childNodes[0].data
AirData[‘airlineStop‘] =node.getElementsByTagName(‘AirlineStop‘)[0].childNodes[0].data
AirData[‘week‘] =node.getElementsByTagName(‘Week‘)[0].childNodes[0].data
allData.append(AirData)
print allData
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。