码迷,mamicode.com
首页 > 其他好文 > 详细

贴吧爬虫入门

时间:2016-05-13 07:37:01      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

  

#saved the baidu tieba webpage

import string, urllib2

def baidu_tieba(url,begin_page,end_page):
    for i in range(begin_page,end_page+1,50):
        sName=string.zfill(i,5)+‘.html‘
        print ‘You are downloading the No: ‘ +str(i)+‘ web page,and will be saved as ‘+sName+‘.....‘
        f=open(sName,‘w+‘)# New open the file with ‘w‘
        m=urllib2.urlopen(url+str(i)).read()#open the web page and read it
        f.write(m)#write the web page to new file
        f.close()#cloase file


bdurl=str(raw_input(u‘please input tieba site, delete pn=number:\n‘))
begin_page=int(raw_input(‘enter start page number:\n‘))
end_page=int(raw_input(‘enter end page number:\n‘))

baidu_tieba(bdurl,begin_page,end_page)

  

贴吧爬虫入门

标签:

原文地址:http://www.cnblogs.com/sinbad-li/p/5484803.html

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