|
@@ -38,12 +38,12 @@ def indent(elem, level=0):
|
|
|
response = requests.get("https://hhh.com.tw/sitemap.xml")
|
|
|
soup = BeautifulSoup(response.text, "html.parser")
|
|
|
|
|
|
-path = 'output.xml'
|
|
|
+path = 'tmp.xml'
|
|
|
f = open(path, 'w')
|
|
|
f.write(soup.prettify())
|
|
|
f.close()
|
|
|
|
|
|
-tree = XET.parse('output.xml') # 以XET套件載入XML檔案
|
|
|
+tree = XET.parse('tmp.xml') # 以XET套件載入XML檔案
|
|
|
old_root = tree.getroot()
|
|
|
|
|
|
#創建根節點
|
|
@@ -54,7 +54,7 @@ a.attrib = {"xmlns":"http://www.sitemaps.org/schemas/sitemap/0.9","xmlns:xhtml":
|
|
|
#創建elementtree對象,寫文件
|
|
|
indent(a,0)
|
|
|
tree = ET.ElementTree(a)
|
|
|
-tree.write("writeXml.xml",encoding="utf-8", xml_declaration=True)
|
|
|
+tree.write("sitemap_new.xml",encoding="utf-8", xml_declaration=True)
|
|
|
|
|
|
print("add old data ... ")
|
|
|
|
|
@@ -77,7 +77,7 @@ for child in old_root :
|
|
|
a.append(b)
|
|
|
|
|
|
indent(a,0)
|
|
|
-tree.write("writeXml.xml",encoding="utf-8", xml_declaration=True)
|
|
|
+tree.write("sitemap_new.xml",encoding="utf-8", xml_declaration=True)
|
|
|
|
|
|
print("add new data ... ")
|
|
|
|
|
@@ -107,4 +107,4 @@ with open("Table.csv",newline="",encoding="utf-8")as file:
|
|
|
a.append(orders)
|
|
|
|
|
|
indent(a,0)
|
|
|
-tree.write("writeXml.xml",encoding="utf-8", xml_declaration=True)
|
|
|
+tree.write("sitemap_new.xml",encoding="utf-8", xml_declaration=True)
|