Skip to main content
 首页 » 编程设计

python之如何从 Python 中的 Soap 响应中提取特定信息 (pysimplesoap)

2024年11月01日9insus

我开始使用 pysimplesoap 在 python 中编写代码。首先针对 Internet 上可用的服务进行测试。我一直在尝试解析 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”中提取等于 True 的 GoodEmail 值,并将其存储在名为“result”的变量中。 我尝试了各种各样的事情,但没有成功。 我必须承认我是 Python 的新手,非常感谢知识渊博的人的帮助!

请您参考如下方法:

您得到的响应是一个 Python dict。您可以像这样访问 GoodEmail 值:

result = response['VerifyEmailResult']['GoodEmail'] 

您可以在此处阅读有关 Python 数据类型的更多信息:http://docs.python.org/2/library/stdtypes.html