当前位置:主页 > 软件编程 > Python代码 >

ptyhon实现sitemap生成示例

时间:2021-06-08 07:43:22 | 栏目:Python代码 | 点击:

复制代码 代码如下:

# _*_ coding:utf-8 _*_

#xiaohei.python.seo.call.me:)
#win+python2.7.x

id_ = 1
f = open('clubpop%s.xml' % id_, 'w')

for i, line in enumerate(open('suk.csv')):
        if i % 50000==0:
                print i
                f.write('<?xml version="1.0" encoding="UTF-8"?>\n<urlset>\n')

        f.write('''     <url>
                <loc>https://www.jb51.net/review/%s-1-1.html</loc>
        </url>
''' % line.rstrip())
        if i % 50000==49999:
                f.write('</urlset>')
                f.close()
                id_ += 1
                f = open('clubpop%s.xml' % id_, 'w')
f.write('</urlset>')
f.close()

您可能感兴趣的文章:

相关文章