您的位置:首页 > 编程语言 > Python开发

Python获取WebService

2013-04-26 23:40 120 查看
# coding=utf-8
from suds.client import Client
from suds.xsd.doctor import ImportDoctor, Import
from pprint import pprint
# import sys
# default_encoding = 'utf-8'
# if sys.getdefaultencoding() != default_encoding:
#    reload(sys)
#    sys.setdefaultencoding(default_encoding)

url ='http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl'
imp = Import('http://www.w3.org/2001/XMLSchema')    # the schema to import.
imp.filter.add('http://WebXml.com.cn/')  # the schema to import into.
d = ImportDoctor(imp)
client = Client(url, doctor=d)
nms=u"广东"
result = client.service.getSupportCity(nms)
print nms
mylogfile = 'log.txt'
f = open(mylogfile, 'a')
f.write('i am logging! timber!....\n')
#f.write(result)

pprint (result[0][0])
for rt in result[0]:
print rt
f.write(rt)
f.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: