File size: 425 Bytes
a785ccd
 
 
 
 
 
 
1
2
3
4
5
6
7
8
import csv
import xml.etree.ElementTree as ET
w = csv.writer(open("catalog.csv", "w", newline="", encoding="utf-8")); w.writerow(["sku", "title", "price", "stock", "tags"])
for p in ET.parse("catalog.xml").getroot().findall("product"):
    st = p.find("stock")
    w.writerow([p.get("sku"), p.findtext("title"), p.findtext("price"), "" if st is None else st.text,
                ";".join(t.text for t in p.findall("tag"))])