python爬虫教程之爬取百度贴吧并下载的示例

yipeiwu_com7年前Python爬虫

测试url:http://tieba.baidu.com/p/27141123322?pn=
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)

相关文章

Python大数据之网络爬虫的post请求、get请求区别实例分析

本文实例讲述了Python大数据之网络爬虫的post请求、get请求区别。分享给大家供大家参考,具体如下: 在JetBrains PyCharm 2016.3软件中编写代码前,需要指定p...

python通过伪装头部数据抵抗反爬虫的实例

0x00 环境 系统环境:win10 编写工具:JetBrains PyCharm Community Edition 2017.1.2 x64 python 版本:python-3.6...

python爬虫之百度API调用方法

python爬虫之百度API调用方法

调用百度API获取经纬度信息。 import requests import json address = input('请输入地点:') par = {'address': add...

基于python 爬虫爬到含空格的url的处理方法

道友问我的一个问题,之前确实没遇见过,在此记录一下。 问题描述 在某网站主页提取url进行迭代,爬虫请求主页时没有问题,返回正常,但是在访问在主页提取到的url时出现了400状态码(40...

python3 Scrapy爬虫框架ip代理配置的方法

python3 Scrapy爬虫框架ip代理配置的方法

什么是Scrapy?   Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架,非常出名,非常强悍。所谓的框架就是一个已经被集成了各种功能(高性能异步下载,队列,分布式,...