从Django中的request.post获取XML数据

时间:2020-08-22 18:13:41

标签: django xml

我正在Django中发送这样的请求:

response = requests.post('https://ws.sandbox.pagseguro.uol.com.br/v2/transactions', headers=headers,
                         params=params, data=data_ps)

当我print(response.text)时,我得到以下答案:

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<transaction>
  <date>2020-08-22T14:57:23.000-03:00</date>
  <code>CCBA67EC-D4C8-42F2-BC84-15C910A36B84</code>
</transaction>

如何获取代码编号(CCBA67EC-D4C8-42F2-BC84-15C910A36B84)?

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以使用python untangle模块。 https://untangle.readthedocs.io/en/latest/ 这是模块的链接