前言
繼續幹17題,就是個http2.0協議,有關這個協議的,我之前就出過相關的文章:python爬蟲 - 爬蟲之針對http2.0的某網站爬取
代碼
所以,就不多比比了,直接上代碼:
import httpx headers = { "authority": "match.yuanrenxue.com", 'cookie': 'sessionid=換成你的sessionid', "sec-ch-ua-mobile": "?0", "user-agent": "yuanrenxue.project", "referer": "https://match.yuanrenxue.com/match/17", 'x-requested-with': 'XMLHttpRequest' } def get_page(page=1): url = f"https://match.yuanrenxue.com/api/match/17?page={page}" with httpx.Client(headers=headers, http2=True) as client: response = client.get(url) result = response.json() print(2312312, response) data = result.get('data') print(12312312, data) return [d.get('value') for d in data] def get_data(): end = 0 for i in range(1, 6): temp_list = get_page(i) some = sum(temp_list) end += some print('end', end) get_data()
執行結果:
提交:
完畢
結語
知道http2.0的就很簡單,不知道的就會懷疑人生