0

I have to request to the page that returns xml format. I suppose to work with data I get, so in case it will be json data, I would write something like

if response.content:
    try:
        res_decoded = response.json()

But what if I know It is data in format xml, how does this part of code should look? Just simply confused

Vasilis G.
  • 7,556
  • 4
  • 19
  • 29
Adiia
  • 77
  • 2
  • 8

1 Answers1

0

You need to use an element tree. Thankfully, python has support for this built in.

import xml.etree.ElementTree as ET
tree = ET.parse('data.xml')
root = tree.getroot()

source: https://docs.python.org/2/library/xml.etree.elementtree.html