Parse XML SOAP response with Python

前端 未结 2 1960
后悔当初
后悔当初 2021-01-03 09:30

I want parse this response from SOAP and extract text between :




        
相关标签:
2条回答
  • 2021-01-03 09:30

    I have the same format but multiple child tags as below. How can I extract the data.

    <LoginResponse xmlns="http://tempuri.org/wsSalesQuotation/Service1">
            <LoginResult>45eeadF43423KKmP33</LoginResult>
    </LoginResponse>
    <LoginResponse xmlns="http://tempuri.org/wsSalesQuotation/Service1">
            <LoginResult>45eeadF43423KKmP33</LoginResult>
    </LoginResponse>
    
    0 讨论(0)
  • 2021-01-03 09:56
    import xml.etree.ElementTree as ET
    tree = ET.parse('soap.xml')    
    
    print tree.find('.//{http://tempuri.org/wsSalesQuotation/Service1}LoginResult').text
    
    
    >>45eeadF43423KKmP33
    

    instead of print, do something useful to it.

    0 讨论(0)
提交回复
热议问题