grequests如何安装呢?

pip install grequests
# -*- coding: utf-8 -*-
"""
@Time: 2018/1/21
@Author: songhao
@微信公众号: zeropython
@File: Requests_Gevent.py
""

[code lang="python"]
import grequests
import json

# 构建urls
urls = ["http://lab.crossincode.com/recite/chap?c={}".format(x) for x in range(1, 11)]

# 请求队列,还未发出请求
rs = (grequests.get(u) for u in urls)

# 批量发出请求,得到响应的列表resps
resps = grequests.map(rs)


def get_words(ht):
    dc = json.loads(ht)
    print(dc['voca'])


for resp in resps:
    # 解析出单词的信息。
    get_words(resp.text)

查看结果:

做爬虫你不会不知道Grequests库吧?(异步请求)-Python 技术分享 Java技术分享 Python 爬虫技术_微信公众号:zeropython—昊天博客
HTTPX 基础教程-新乡seo|网站优化,网站建设_微信公众号:zeropython—昊天博客