一、数据接口分析
主页地址:猿人学第三题
1、抓包
通过抓包可以发现数据接口是api/match/3
2、判断是否有加密参数
- 请求参数是否加密?
无 - 请求头是否加密?
无 - 响应是否加密?
无 - cookie是否加密?
无
二、发送请求
因为没有任何的加密参数,所以先尝试直接请求。直接发送请求时,却发现返回的响应内容并不是想要的数据内容,而是乱码
此时,就需要再次回到浏览器中,观察抓包与我们的请求有何不同。可以发现,浏览器在每次发包获取数据时,都是发了两个包,先使用post请求jssm
这个接口,再请求数据接口
所以我们在发送请求时也要先请求jssm
接口,再请求数据
源代码:
"""
Email:912917367@qq.com
Date: 2023/8/1 17:31
"""
import requestsheaders = {'content-length': '0','pragma': 'no-cache','cache-control': 'no-cache','sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"','sec-ch-ua-mobile': '?0','user-agent': 'yuanrenxue.project','sec-ch-ua-platform': '"Windows"','accept': '*/*','origin': 'https://match.yuanrenxue.cn','sec-fetch-site': 'same-origin','sec-fetch-mode': 'cors','sec-fetch-dest': 'empty','referer': 'https://match.yuanrenxue.cn/match/3','accept-encoding': 'gzip, deflate, br','accept-language': 'zh-CN,zh;q=0.9',
}
cookies = {"Hm_lvt_c99546cf032aaa5a679230de9a95c7db": "1690853737,1690856872","Hm_lvt_9bcbda9cbf86757998a2339a0437208e": "1690856502,1690856877","no-alert3": "true","Hm_lvt_434c501fe98c1a8ec74b813751d4e3e3": "1690856417,1690880272","Hm_lpvt_434c501fe98c1a8ec74b813751d4e3e3": "1690880272","tk": "-3089194693148654306","sessionid": "25yk747fkvd7oiq7oxa6wcagntbj5iso","yuanrenxue_cookie": "1690938760^|KR179JVCQjsT1ll2uyFkuKseGkWgobwDRWVWImdGVZkIC8wndqjpczGZQjnrt4amO4IKe2TKyZ4hljQ2gyj6b0uYEEWL","Hm_lpvt_9bcbda9cbf86757998a2339a0437208e": "1690938771","Hm_lpvt_c99546cf032aaa5a679230de9a95c7db": "1690938773"
}
session = requests.session()
session.headers = headersurl = "https://match.yuanrenxue.cn/jssm"data_dict = {}for page in range(1, 6):response = session.post(url, cookies=cookies)print(response)url_p = 'https://match.yuanrenxue.cn/api/match/3?page={}'.format(page)response = session.get(url=url_p, cookies=cookies)data = response.json()['data']for item in data:if item['value'] in data_dict:data_dict[item['value']] += 1else:data_dict[item['value']] = 1print(data_dict)