贴吧爬虫入门

此博客为转载内容,转载自https://www.cnblogs.com/sinbad-li/p/5484803.html ,原内容可能与爬虫相关。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  

#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)

  

转载于:https://www.cnblogs.com/sinbad-li/p/5484803.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值