Python获取WebService
# 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()