"```python

import requests

from fake_useragent import UserAgent # 随机ua库

class Boring():

def __init__(self, page_scope=(4, 7)):
"""
:param page_scope: 页码范围
"""
self.page_scope = page_scope
self.all_id = self.get_all_company_id()
self.enterprise_info = self.get_all_company_info()
self.show_enterprise_info() @property
def firefox_ua(self):
"""返回随机火狐UA头"""
ua = UserAgent(use_cache_server=False)
return {'User-Agent': ua.Firefox} # ua.Firefox:随机生成火狐浏览器UA def get_all_company_id(self):
"""
将返回指定页码数内的公司的id
:param start_page: 起始页码
:param end_page: 结束页码
"""
all_id = {}
url = 'http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsList' # 此连接见图1
for page in range(self.page_scope[0], self.page_scope[1] + 1):
json_text = requests.post(url, data=self.post_data(page), headers=self.firefox_ua).json()
current_page_all_id = [dict['ID'] for dict in json_text['list']]
all_id.setdefault(page, current_page_all_id)
return all_id def get_all_company_info(self):
"""开始获取公司信息"""
url = 'http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsById' # 见图3
enterprise_info = {}
for page in self.all_id:
for id in self.all_id.get(page):
response = requests.post(url, data={'id': id}, headers=self.firefox_ua) # data={'id': id}:见图4
if response.headers['Content-Type'] == 'application/json;charset=UTF-8':
json_text = response.json()
enterprise_info.setdefault(json_text.get('businessPerson'), json_text.get('epsName'))
# 这里仅获取企业负责人和企业名
return enterprise_info def show_enterprise_info(self):
[print(k, v) for k, v in self.enterprise_info.items()] def post_data(self, page):
"""获取公司列表时要提交的form"""
return {
'on': 'true',
'page': page,
'pageSize': '15',
'productName': '',
'conditionType': '1',
'applyname': '',
'applysn': '',
} # 见图2

go

Boring()



"

【Python requests多页面爬取案例】的更多相关文章

  1. python requests库网页爬取小实例:亚马逊商品页面的爬取

    由于直接通过requests.get()方法去爬取网页,它的头部信息的user-agent显示的是python-requests/2.21.0,所以亚马逊网站可能会拒绝访问.所以我们要更改访问的头部信 ...

  2. python requests库网页爬取小实例:百度/360搜索关键词提交

    百度/360搜索关键词提交全代码: #百度/360搜索关键词提交import requestskeyword='Python'try: #百度关键字 # kv={'wd':keyword} #360关 ...

  3. Python Requests库网络爬取全代码

    #爬取京东商品全代码 import requestsurl = "http://item.jd.com/2967929.html"try: r = requests.get(url ...

  4. python Requests库网络爬取IP地址归属地的自动查询

    #IP地址查询全代码import requestsurl = "http://m.ip138.com/ip.asp?ip="try: r = requests.get(url + ...

  5. Python Requests库入门——应用实例-京东商品页面爬取+模拟浏览器爬取信息

    京东商品页面爬取 选择了一款荣耀手机的页面(给华为打广告了,荣耀play真心不错) import requests url = "https://item.jd.com/7479912.ht ...

  6. 使用requests简单的页面爬取

    首先安装requests库和准备User Agent 安装requests直接使用pip安装即可 pip install requests 准备User Agent,直接在百度搜索"UA查询 ...

  7. Python使用urllib,urllib3,requests库+beautifulsoup爬取网页

    Python使用urllib/urllib3/requests库+beautifulsoup爬取网页 urllib urllib3 requests 笔者在爬取时遇到的问题 1.结果不全 2.'抓取失 ...

  8. python爬爬爬之单网页html页面爬取

    python爬爬爬之单网页html页面爬取 作者:vpoet mail:vpoet_sir@163.com 注:随意copy 不用告诉我 #coding:utf-8 import urllib2 Re ...

  9. Python爬虫实例:爬取B站《工作细胞》短评——异步加载信息的爬取

    很多网页的信息都是通过异步加载的,本文就举例讨论下此类网页的抓取. <工作细胞>最近比较火,bilibili 上目前的短评已经有17000多条. 先看分析下页面 右边 li 标签中的就是短 ...

随机推荐

  1. gulp常用插件之gulp-eslint使用

    更多gulp常用插件使用请访问:gulp常用插件汇总 ** gulp-eslint**这是一个用于识别和报告在ECMAScript/JavaScript代码中找到的模式的Gulp插件.. 更多使用文档 ...

  2. numpy reshape -1

    来源:https://www.zhihu.com/question/52684594 z = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12] ...

  3. linux安装Nginx 以及 keepalived 管理Nginx

    linux安装Nginx 1.1将Nginx素材内容上传到/usr/local目录(pcre,zlib,openssl,nginx)(注意:必须登录用对这个文件具有操作权限的) 1.2安装pcre库 ...

  4. 限定输入框只能输入数字, TextBox的TextChanged事件调用

    /// <summary> /// 限定输入框只能输入数字, TextBox的TextChanged事件调用 /// </summary> /// <param name ...

  5. Win10桌面菜单弹出cmd解决办法

    现象 Win10右键菜单打开弹出命令提示符 原有个性化.显示设置.网络和Internet设置无法使用 解决 注册表定位到HKEY_CURRENT_USER\Software\Classes\ ms-s ...

  6. Exec msdb.dbo.sp_send_dbmail 参数详解(SQL Server 存储过程发邮件)

    转载oriency755 发布于2012-12-04 11:34:45 阅读数 6870 收藏   sp_send_dbmail [ [ @profile_name = ] 'profile_name ...

  7. day6 基础总结和编码方式

    # = 赋值 == 比较值是否相等 is 比较内存地址 li1 = [1, 2, 3] li2 = li1 print(li1 is li2) print(id(li1), id(li2)) #数字, ...

  8. Jmeter实践

    Jmeter时间戳函数 详见:https://blog.csdn.net/dreamtl/article/details/68957447 ${__timeShift(yyyy-MM-dd HH:mm ...

  9. PAT (Basic Level) Practice (中文)1043 输出PATest (20 分)

    给定一个长度不超过 1 的.仅由英文字母构成的字符串.请将字符重新调整顺序,按 PATestPATest.... 这样的顺序输出,并忽略其它字符.当然,六种字符的个数不一定是一样多的,若某种字符已经输 ...

  10. Verilog-case、casez和casex的区别

    参考博客:https://www.cnblogs.com/guolongnv/articles/6906929.html 1.基本概念 1)?表示z,而不是“dont care” 2)区分: case ...