python爬虫教程之爬取百度贴吧并下载的示例
程序员文章站
2023-11-04 22:19:04
测试url:=begin 1end 4复制代码 代码如下:import string ,urllib2
def baidu_tieba...
测试url:=
begin 1
end 4
复制代码 代码如下:
import string ,urllib2
def baidu_tieba(url,begin_page,end_page):
for i in range(begin_page, end_page+1):
sname = string.zfill(i,5)+ '.html'
print '正在下载第' + str(i) + '个网页,并将其存储为' + sname + '..........'
f = open (sname,'w+')
m = urllib2.urlopen(url + str(i)).read()
f.write(m)
f.close()
bdurl = str(raw_input('url: \n'))
begin_page = int(raw_input('begin :\n'))
end_page = int(raw_input('end : \n'))
baidu_tieba(bdurl,begin_page,end_page)