使用Python解析XML SOAP响应

Man*_*rra 2 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>
Run Code Online (Sandbox Code Playgroud)

我如何使用XML Python Libs来做到这一点?

Gjo*_*dis 6

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

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


>>45eeadF43423KKmP33
Run Code Online (Sandbox Code Playgroud)

而不是打印,做一些有用的事情.