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常用数据类型之间的转换总结

函数 描述 int(x [,base]) 将x转换为一个...

python同时替换多个字符串方法示例

本文介绍了python同时替换多个字符串方法示例,分享给大家,具体如下: import re words = ''' 钟声响起归家的讯号 在他生命里 仿佛带点唏嘘...

python多线程http下载实现示例

测试平台 Ubuntu 13.04 X86_64 Python 2.7.4 花了将近两个小时, 问题主要刚开始没有想到传一个文件对象到线程里面去, 导致下载下来的文件和源文件MD5不一样...

Python常用模块介绍

python除了关键字(keywords)和内置的类型和函数(builtins),更多的功能是通过libraries(即modules)来提供的。 常用的libraries(module...

numpy下的flatten()函数用法详解

flatten是numpy.ndarray.flatten的一个函数,其官方文档是这样描述的: ndarray.flatten(order='C') Return a copy of...