Я попробовал следующее: < /p>
Код: Выделить всё
Python 3.13.3 (main, Apr 8 2025, 13:54:08) [Clang 16.0.0 (clang-1600.0.26.6)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
>>> xml = '''
...
...
...
... soap:Sender
...
...
... ns1:unauthorized
...
...
...
...
... AccessResult: result: Access Denied | AuthenticationAsked: true |
... ErrorCode: IDP_ERROR:
... 137 | ErrorReason: null
...
...
...
... SystemError
... IDP_ERROR: 137 |
... ErrorReason: null
...
...
...
...
... '''
>>> root = etree.fromstring(xml)
>>> print(root)
>>> ns = { 'soap':'http://www.w3.org/2003/05/soap-envelope', 'ns1':'http://docs.oasis-open.org/wss/oasis-ws ... xt-1.1.xsd"' }
>>> print(root.xpath('//soap:Subcode/soap:Value',namespaces=ns)[0].text)
ns1:unauthorized
>>> print(root.xpath('//soap:Reason/soap:Text',namespaces=ns)[0].text)
AccessResult: result: Access Denied | AuthenticationAsked: true |
ErrorCode: IDP_ERROR:
137 | ErrorReason: null
>>> print(root.xpath('//soap:Detail/WebServiceFault/message',namespaces=ns)[0].text)
Traceback (most recent call last):
File "
", line 1, in
print(root.xpath('//soap:Detail/WebServiceFault/message',namespaces=ns)[0].text)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
По какой -то причине текст элемента сообщения, который я не могу получить.
Цените любую помощь.
Подробнее здесь: https://stackoverflow.com/questions/796 ... e-elements