Python爬虫学习(1):百度贴吧

来源:互联网 发布:mysql navicat 破解码 编辑:程序博客网 时间:2024/05/21 06:14

第一次学习爬虫:只用了urllib的函数。不需要跳过登陆,最简单的爬虫。

爬三页帖子的页面,然后作为html保存起来,只是要注意

def scrap(url,begin,end):    for i in range(begin,end+1):        filename = 'file{}.html'.format(str(i).zfill(3))        print(url+str(i))        response = url_req.urlopen(url+str(i))        with open(filename,'wb') as f:            f.write(response.read())burl_ = 'http://tieba.baidu.com/f?kw=%E7%94%B5%E5%AD%90%E7%A7%91%E6%8A%80%E5%A4%A7%E5%AD%A6&ie=utf-8&pn='burl =   'http://tieba.baidu.com/p/4711180166?pn='burl_2 = 'http://tieba.baidu.com/p/3138733512?pn='begin = 1end = 3scrap(burl,begin,end)
0 0
原创粉丝点击