10:Python爬虫|猿人学第十七题|天杀的http2.0

2022-01-07  本文已影响0人  HAO延WEI

前言:我们来了解一下http2.0http2.0是为了加快网页渲染速度所发布的新的协议,我们之前使用的request只能够get请求到http1.0的数据而http2.0就没有办法了,所以为了爬取http2.0的数据,需要安装httpx(pip3 install httpx)

如何查看链接协议

谷歌浏览器: http协议版本在这里查看:----> 网络 ----> 右击---->勾选协议---->刷新链接


火狐浏览器: http协议版本在这里查看: ----> 网络 ----> 找到对应链接 ---->查看消息头

1. 代码

# -*- coding:utf-8 -*-

import httpx

client = httpx.Client(http2=True)

headers = {
    'authority': 'match.yuanrenxue.com',
    'pragma': 'no-cache',
    'cache-control': 'no-cache',
    'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"',
    'accept': 'application/json, text/javascript, */*; q=0.01',
    'x-requested-with': 'XMLHttpRequest',
    'sec-ch-ua-mobile': '?0',
    'user-agent': 'yuanrenxue.project',
    'sec-ch-ua-platform': '"macOS"',
    'sec-fetch-site': 'same-origin',
    'sec-fetch-mode': 'cors',
    'sec-fetch-dest': 'empty',
    'referer': 'https://match.yuanrenxue.com/match/17',
    'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
    'cookie': '你的cookie',
}

result = 0

response = client.get(f'https://match.yuanrenxue.com/api/match/17', headers=headers)

print(response.json())
print(response)
上一篇 下一篇

猜你喜欢

热点阅读