ptyhon实现sitemap生成示例

yipeiwu_com6年前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>//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()

相关文章

python if not in 多条件判断代码

python if not in 多条件判断代码

百度作业帮提问: python if not in 多条件 判断怎么写 s = ['1','2'] 判断条件 sta = "12345" 正常的是这样的, if "1" not in s...

python内存动态分配过程详解

python内存动态分配过程详解

一、前言 大多数编译型语言,变量在使用前必须先声明,其中C语言更加苛刻:变量声明必须位于代码块最开始,且在任何其他语句之前。其他语言,想C++和java,允许“随时随地”声明变量,比如...

python检查指定文件是否存在的方法

本文实例讲述了python检查指定文件是否存在的方法。分享给大家供大家参考。具体如下: import os def file_exists(file_name): if os....

python矩阵的转置和逆转实例

如下所示: # 矩阵的转置 def transpose(list1): return [list(row) for row in zip(*list1)] list1 = [[...

Python语法分析之字符串格式化

前序 There should be one - and preferably only one - obvious way to do it. ———— the Zen of Pyt...