====== XML ====== ===== Utiliser ElementTree ===== * Doc : [[https://docs.python.org/3/library/xml.etree.elementtree.html]] 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")) ===== Utiliser la librairie lxml ===== * Tutorial **lxml** : [[https://lxml.de/tutorial.html]] * Infos: [[https://python.doctor/page-xml-python-xpath]] pip install lxml ===== Utiliser BeautifulSoup4 ===== 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