Skip to content

Instantly share code, notes, and snippets.

@StanGirard
Created February 27, 2020 22:06
Show Gist options
  • Save StanGirard/204eb424781b187f46771064e5819666 to your computer and use it in GitHub Desktop.
Save StanGirard/204eb424781b187f46771064e5819666 to your computer and use it in GitHub Desktop.
Parsing an API XML Response Data - Python
import requests
import xml.etree.ElementTree as ET
r = requests.get('https://www.washingtonpost.com/arcio/news-sitemap/')
print(r.content)
xmlDict = {}
root = ET.fromstring(r.content)
for child in root.iter('*'):
print(child.tag)
for sitemap in root:
children = sitemap.getchildren()
xmlDict[children[0].text] = children[1].text
print (xmlDict)
@ChrisAlbertsen
Copy link

for sitemap in root:    
    children = sitemap.getchildren()

getchildren() is deprecated according to documentation.

The recommended is now list(sitemap)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment