python dom 解析 webservice xml

# -*- coding: UTF-8 -*-
__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

python dom 解析 webservice xml,布布扣,bubuko.com

python dom 解析 webservice xml

上一篇:Google kaptcha动态生成图片验证码的使用


下一篇:java线程代码篇