Created
February 27, 2020 22:06
-
-
Save StanGirard/204eb424781b187f46771064e5819666 to your computer and use it in GitHub Desktop.
Parsing an API XML Response Data - Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
getchildren() is deprecated according to documentation.
The recommended is now list(sitemap)