Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Parse XML from website using python

I’m trying parse XML from URL, but i got error FileNotFoundError

where I’m doing wrong?

Here’s my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import xml.etree.ElementTree as ET
import requests
url = "http://cs.stir.ac.uk/~soh/BD2spring2022/assignmentdata.php"
params = {'data':'spurpyr'}
response = requests.get (url, params)
xml_content = response.content

tree = ET.parse(xml_content)
root = tree.getroot()
print(root.tag)

>Solution :

ET.parse parses from a file, instead of ET.parse try using ET.fromstring and that would probably help. I can’t test your specific case since the URL you have written is giving me an error. So, try changing your code to this

import xml.etree.ElementTree as ET
import requests
url = "http://cs.stir.ac.uk/~soh/BD2spring2022/assignmentdata.php"
params = {'data':'spurpyr'}
response = requests.get (url, params)
xml_content = response.content

root = ET.fromstring(xml_content)
print(root.tag)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading