文章目录
前言
当需要使用python爬虫同时访问大量数据时,使用grequests库进行并行访问。相比于requests的重复建立连接串行访问,grequests可以为我们的访问提速不少。
一、安装
pip install grequests
二、简易使用
使用grequests进行访问时,将所有请求放入一个列表中,如此处的req_list。然后调用grequests的map方法,返回值也是一个list,我这里用response_list接收。response_list中的每一个元素都是一个<class ‘requests.models.Response’>类,有status_code、text、json等量。代码如下(示例):
import grequests
req_list = [
grequests.get("https://www.baidu.com")