目标
考点:天杀的http2.0
任务十七:抓取这5页的数字,计算加和并提交结果
https://match.yuanrenxue.com/match/17
分析
这里因为之前经历过2.0的坑,所以不需要过多分析。
可以看了一下遇到http2.0的情况时,爬虫该如何去做?
还原
# ==================================
# --*-- coding: utf-8 --*--
# @Time : 2022/9/22 16:00
# @Author : Gorkys
# @FileName: main.py
# @Software: PyCharm
# @describe: 猿人学第十七题
# ==================================
# pip install httpx[http2]
import httpx
requests = httpx.Client(http2=True)
count = 0
def getPriceList(page):
global count
cookies = {
'sessionid': 'woq4i0ilxxoh74qnx6nj67fdc38mue8m'
}
headers = {
'referer': 'https://match.yuanrenxue.com/match/17',
'user-agent': "yuanrenxue.project"
}
params = {
"page": str(page)
}
response = requests.get('https://match.yuanrenxue.com/api/match/17', params=params, cookies=cookies,
headers=headers)
data = response.json()["data"]
for i in range(len(data)):
count += data[i]["value"]
for i in range(5):
getPriceList(i + 1)
print(count)