码迷,mamicode.com
首页 > 编程语言 > 详细

python_小爬虫

时间:2014-11-06 16:36:55      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   os   for   sp   

import urllib.request as request
import urllib.parse as parse
import string
print("""
+++++++++++++++++++++++
  name:cphmvp
  version: python3.3
+++++++++++++++++=++++
     """)
def baidu_tieba(url, begin_page, end_page):
    for i in range(begin_page, end_page + 1):
        sName = str(i).zfill(5)+.html
        print(正在下载第+str(i)+个页面, 并保存为+sName)
        m = request.urlopen(url+str(i)).read()
        with open(sName,wb) as file:
            file.write(m)
        file.close()
if __name__ == "__main__":
    url = "http://tieba.baidu.com/p/"
    begin_page = 1
    end_page = 3
    baidu_tieba(url, begin_page, end_page)

 

python_小爬虫

标签:style   blog   http   io   color   ar   os   for   sp   

原文地址:http://www.cnblogs.com/cphmvp/p/4078977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!