当前位置:首页python > 正文

【内部资料】站点地图sitemap代码

作者:野牛程序员:2023-09-24 07:49:49python阅读 2565

代码一:

def generate_xml_url(loc, lastmod, priority):
    template = """<url>
    <loc>{}</loc>
    <lastmod>{}</lastmod>
    <priority>{}</priority>
</url>"""
    return template.format(loc, lastmod, priority)

# 生成从1到3803的XML块列表
urls = []
# for i in range(1, 3804):
# for i in range(3804, 4043):
for i in range(3804, 4665):
    loc = f"http://yncoders.com/show/{i}"
    lastmod = "2023-08-10T09:57:41+00:00"
    priority = "0.64"
    urls.append(generate_xml_url(loc, lastmod, priority))

# 将列表中的XML块合并成一个字符串
xml_content = "\\n".join(urls)

# 将XML内容写入文件
output_file_path = "output20230810.xml"
with open(output_file_path, "w") as file:
    file.write(xml_content)

print(f"XML content exported to '{output_file_path}'.")

代码二:

def generate_xml_url(loc):
    template = """{}"""
    return template.format(loc)

# 生成从1到3803的XML块列表
urls = []
# for i in range(1, 3804):
for i in range(3804, 4043):
    loc = f"http://yncoders.com/show/{i}"
    urls.append(generate_xml_url(loc))

# 将列表中的XML块合并成一个字符串
xml_content = "\\n".join(urls)

# 将XML内容写入文件
output_file_path = "outputhtr20230801.xml"
with open(output_file_path, "w") as file:
    file.write(xml_content)

print(f"XML content exported to '{output_file_path}'.")


野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892
野牛程序员教少儿编程与信息学竞赛-微信|电话:15892516892
相关推荐

最新推荐

热门点击