我想解析来自 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/