python - 使用 Python 解析 XML SOAP 响应

标签 python xml soap

我想解析来自 SOAP 的响应并提取 <LoginResult> 之间的文本:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
     <soap:Body>
      <LoginResponse xmlns="http://tempuri.org/wsSalesQuotation/Service1">
        <LoginResult>45eeadF43423KKmP33</LoginResult>
      </LoginResponse>
     </soap:Body>
</soap:Envelope>

如何使用 XML Python 库来实现?

最佳答案

import xml.etree.ElementTree as ET
tree = ET.parse('soap.xml')    

print tree.find('.//{http://tempuri.org/wsSalesQuotation/Service1}LoginResult').text


>>45eeadF43423KKmP33

与其打印,不如做一些对它有用的事情。

关于python - 使用 Python 解析 XML SOAP 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14828379/

相关文章:

Python slackclient oauth.access 调用返回 'invalid_code' 错误

python - PyQt5 连接在这种情况下不起作用 : item cannot be converted to PyQt5. QtCore.QObject

java - Jena model.write 获取 InvalidPropertyURIException

java - Xpath解析: The prefix for element is not bound

java - Coldfusion WSS4J Java Soap 签名者证书在首次签名后消失

xml - 从 WSDL 文件确定端点

python - 如何从数据库中检索列名

java - 如何在滚动 Activity 下放置广告 View 横幅?

soapui SOAP 数字签名

python - 在 Python 中,说我们 "override"内置运算符的行为准确吗?