1,调用方式:
使用suds这个第三方模块,贴出代码:
from suds.client import Client seedStr = 'http://www.webxml.com.cn/WebServices/TraditionalSimplifiedWebService.asmx?wsdl' client = Client(seedStr) print(client)
成功,打印出cilent的值:
2,固定代码调用webservice接口中的方法,贴代码:
#方法作用:把繁体字转换为简体字
result = client.service.toSimplifiedChinese('龍的傳人')
print(result)
3,用字符串形式,动态调用接口方法,贴代码:
import suds
from suds.client import Client
seedStr = 'http://www.webxml.com.cn/WebServices/TraditionalSimplifiedWebService.asmx?wsdl'
client = Client(seedStr)
#print(client)
client = suds.client.Client(seedStr)
s = getattr(client.service, 'toSimplifiedChinese')('龍的傳人')
#利用getattr实现用字符串‘toSimplifiedChinese’,实现接口动态调用。
print(s)