mirror of
https://github.com/luzhisheng/js_reverse.git
synced 2025-04-22 15:19:39 +08:00
猿人学第17题-天杀的http2.0
This commit is contained in:
parent
85b66c817a
commit
6d0bad2592
11
猿人学第17题-天杀的http2.0/readme.md
Normal file
11
猿人学第17题-天杀的http2.0/readme.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
HTTP/2.0 - 最新超强反爬虫方案,禁用所有 HTTP 1.x 的请求
|
||||||
|
|
||||||
|
现在很多爬虫库其实对 HTTP/2.0 支持得不好,比如大名鼎鼎的 Python 库 —— requests,到现在为止还只支持 HTTP/1.1,啥时候支持 HTTP/2.0 还不知道。
|
||||||
|
|
||||||
|
地址 https://blog.csdn.net/weixin_42277380/article/details/117440390
|
||||||
|
|
||||||
|
控制查看 h2 请求
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
[案例.py](./案例.py)
|
26
猿人学第17题-天杀的http2.0/案例.py
Normal file
26
猿人学第17题-天杀的http2.0/案例.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import requests
|
||||||
|
from hyper.contrib import HTTP20Adapter
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
url_ = 'https://match.yuanrenxue.com/api/match/17?page={}'
|
||||||
|
headers_ = {
|
||||||
|
"User-Agent": "yuanrenxue.project",
|
||||||
|
"cookie": "sessionid=nbfta7wd1srjcwh558k0vh1mt0tq7i1v"
|
||||||
|
}
|
||||||
|
# 创建session对象,并设置请求头
|
||||||
|
s = requests.session()
|
||||||
|
s.headers = headers_
|
||||||
|
# 使用http2.0
|
||||||
|
s.mount('https://match.yuanrenxue.com', HTTP20Adapter())
|
||||||
|
num = 0
|
||||||
|
for i in range(5):
|
||||||
|
# 发送请求
|
||||||
|
json_data = s.get(url_.format(i + 1)).json()
|
||||||
|
print(json_data)
|
||||||
|
data_list = json_data.get('data')
|
||||||
|
for j in data_list:
|
||||||
|
print(j.get('value'))
|
||||||
|
j_num = j.get('value')
|
||||||
|
num += j_num
|
||||||
|
print()
|
||||||
|
print('num:', num)
|
Loading…
x
Reference in New Issue
Block a user