如何用Python从Soap响应中提取特定信息(pysimplesoap)
我开始用Python编程,使用的是pysimplesoap库。现在我在测试一个网上的服务。我卡在了如何解析Soap查询的结果上。
#!/usr/bin/python
from pysimplesoap.client import SoapClient
import pysimplesoap
import logging
logging.basicConfig()
client=SoapClient(wsdl="http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx?wsdl",trace=True)
response = client.VerifyEmail(email="a-valid-gmail-address@gmail.com",LicenseKey="?")
print response
我得到了以下结果,这说明Soap请求是成功的:
{'VerifyEmailResult': {'GoodEmail': True, 'LastMailServer': u'gmail-smtp-in.l.google.com', 'ResponseText': u'Mail Server will accept email', 'ResponseCode': 3}}
现在我想从“response”中提取出GoodEmail的值,它等于True,并把这个值存储在一个名为“result”的变量里。我尝试了很多方法,但都没有成功。我必须承认我对Python非常陌生,希望能得到一个懂行的人的帮助!
1 个回答
3
你得到的响应是一个Python的 字典
。你可以这样访问 GoodEmail
的值:
result = response['VerifyEmailResult']['GoodEmail']
你可以在这里了解更多关于Python数据类型的信息: http://docs.python.org/2/library/stdtypes.html