XML-Datei/Bestimmten Tag ausgeben
Verfasst: Mittwoch 22. Februar 2023, 13:50
Hallo,
Ich muß aus mehreren XML-Dateien den Inhalt eines bestimmten Tag (loc) auflisten und habe das so gemacht:
import requests
import xml.etree.ElementTree as ET
#list of xml files
xml_files = ["https://www.anita.com/sitemaps/de/sitemap.xml", "https://www.anita.com/sitemaps/ch/sitemap.xml"]
#iterate through list of xml files
for xml_file in xml_files:
xml_content = requests.get(xml_file).text
tree = ET.fromstring(xml_content)
for url in tree.findall('urlset'):
# print content of specific tag
print(url.find('loc').text)
Die Ausgabe ist gar nichts. Weiß jemand woran das liegt? Ein Beispiel für die XML-Datei ist unter https://www.anita.com/sitemaps/de/sitemap.xml.
Ich muß aus mehreren XML-Dateien den Inhalt eines bestimmten Tag (loc) auflisten und habe das so gemacht:
import requests
import xml.etree.ElementTree as ET
#list of xml files
xml_files = ["https://www.anita.com/sitemaps/de/sitemap.xml", "https://www.anita.com/sitemaps/ch/sitemap.xml"]
#iterate through list of xml files
for xml_file in xml_files:
xml_content = requests.get(xml_file).text
tree = ET.fromstring(xml_content)
for url in tree.findall('urlset'):
# print content of specific tag
print(url.find('loc').text)
Die Ausgabe ist gar nichts. Weiß jemand woran das liegt? Ein Beispiel für die XML-Datei ist unter https://www.anita.com/sitemaps/de/sitemap.xml.