美文网首页
Python网络爬虫之爬取百度贴吧网址并保存

Python网络爬虫之爬取百度贴吧网址并保存

作者: keitwo | 来源:发表于2018-01-15 13:00 被阅读28次

通过urllib2+resquest爬虫百度贴吧网址,并保存至该工作目录下

一、示例代码

示例代码

代码解析:

1.首先定义一个baidu_tieba的函数:def baidu_tieba()

2.抓取的网页给重新命名并保存在工作目录下:

name = string.zfill(i,5) +'.html';

url = urllib2.Request(baurl)

m = urllib2.urlopen(url).read()

f.write(m)

3.手动输入网址、网页的页数等raw_input()

4.调用baidu_tieba的函数:def baidu_tieba()运行程序并查看运行结果

相关文章

网友评论

      本文标题:Python网络爬虫之爬取百度贴吧网址并保存

      本文链接:https://www.haomeiwen.com/subject/eovxoxtx.html