0

I would like to extract some data from an XML file. Here is the XML file:
<post height="4093" score="14" file_url="xxxx" parent_id="" sample_url="xxxx" sample_width="850" sample_height="1202 />"

All I need is to extract the string that is stored file_url. I want this "xxxx".

martineau
  • 119,623
  • 25
  • 170
  • 301
Mejkou
  • 1

1 Answers1

0

You can use xml.etree.ElementTree xml parser:

import xml.etree.ElementTree as ET

xml = '''<post height="4093" score="14" file_url="xxxx" parent_id="" sample_url="xxxx" sample_width="850" sample_height="1202" />'''
root = ET.fromstring(xml)
print(root.attrib['file_url'])
Wasif
  • 14,755
  • 3
  • 14
  • 34