首页 > 其他 > 详细

贴吧爬虫入门

时间:2016-05-13 07:35:48      阅读:227      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!