I have looked at the documentation and other similar questions and can't work out what's going wrong here!
I want to use the XML output from an API.
I have XML that looks a bit like this:
<response>
<lst></lst>
<result>
<doc>
<str name ="pa">1234</str>
<str name ="et">Title 1</str>
<str name ="pb">Publisher 1</str>
<str name ="ur">http://www.exampleone.com</str>
</doc>
<doc>
<str name ="pa">5678</str>
<str name ="et">Title 2</str>
<str name ="pb">Publisher 2</str>
<str name ="ur">http://www.exampletwo.com</str>
</doc>
</result>
I want to get the "pa" for each doc element.
This is the code I am using, but get nothing:
import requests
import xml.etree.ElementTree as ET
r = requests.get("api url goes here")
tree = ET.fromstring(r.content)
for doc in tree.findall("doc"):
pan = doc.find('pa').text
print pan
What am I doing wrong?