import xml.etree.ElementTree as ET tree = ET.parse("yourXMLfile.xml") root = tree.getroot()
for child in root: print(child.tag, child.attrib)
print(root[0][1].text)
print(root.findall("myTag")) print(root[0].find("myOtherTag"))
pip install lxml
pip install beautifulsoup4
from bs4 import BeautifulSoup import requests xmlDict = {} r = requests.get("http://www.site.co.uk/sitemap.xml") xml = r.text soup = BeautifulSoup(xml) sitemapTags = soup.find_all("sitemap") print "The number of sitemaps are {0}".format(len(sitemapTags)) for sitemap in sitemapTags: xmlDict[sitemap.findNext("loc").text] = sitemap.findNext("lastmod").text print xmlDict