From 3d6f24b18f9dd30ce0e08767dc5344add06eae03 Mon Sep 17 00:00:00 2001 From: luzhisheng Date: Sat, 13 Jan 2024 00:06:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../猿人学第17题-天杀的http2.0/ERADME.md | 3 +++ .../猿人学第17题-天杀的http2.0/readme.md | 11 -------- .../猿人学第17题-天杀的http2.0/yrx17.py | 23 ++++++++++++++++ .../猿人学第17题-天杀的http2.0/案例.py | 26 ------------------- 4 files changed, 26 insertions(+), 37 deletions(-) create mode 100644 猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/ERADME.md delete mode 100644 猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/readme.md create mode 100644 猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/yrx17.py delete mode 100644 猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/案例.py diff --git a/猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/ERADME.md b/猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/ERADME.md new file mode 100644 index 0000000..d99d67f --- /dev/null +++ b/猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/ERADME.md @@ -0,0 +1,3 @@ +解题文档 + + https://blog.csdn.net/u010226586/article/details/135563851 \ No newline at end of file diff --git a/猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/readme.md b/猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/readme.md deleted file mode 100644 index 355d212..0000000 --- a/猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/readme.md +++ /dev/null @@ -1,11 +0,0 @@ -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 请求 - -![debugger](../img/76.png) - -[案例.py](./案例.py) \ No newline at end of file diff --git a/猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/yrx17.py b/猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/yrx17.py new file mode 100644 index 0000000..5accc97 --- /dev/null +++ b/猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/yrx17.py @@ -0,0 +1,23 @@ +import requests +from hyper.contrib import HTTP20Adapter + +url_ = 'https://match.yuanrenxue.cn/api/match/17?page={}' +headers_ = { + "User-Agent": "yuanrenxue.project", + "cookie": "sessionid=ieirkmfqa2qsj29uapsh4bdaj59vggj2" +} +# 创建session对象,并设置请求头 +s = requests.session() +s.headers = headers_ +# 使用http2.0 +s.mount('https://match.yuanrenxue.cn', 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: + j_num = j.get('value') + num += j_num +print('num:', num) diff --git a/猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/案例.py b/猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/案例.py deleted file mode 100644 index 97a97c2..0000000 --- a/猿人学Web端爬虫攻防刷题平台/猿人学第17题-天杀的http2.0/案例.py +++ /dev/null @@ -1,26 +0,0 @@ -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)