赞
踩
import time import base64 import hashlib import requests headers = { 'authority': 'www.python-spider.com', 'accept': 'application/json, text/javascript, */*; q=0.01', 'accept-language': 'zh-CN,zh;q=0.9', 'cache-control': 'no-cache', 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', # 'cookie': 'Hm_lvt_337e99a01a907a08d00bed4a1a52e35d=1671613116,1672285285; sessionid=z1kn1ijhnadm2m3hfs77uk93sbt8j4zl; Hm_lpvt_337e99a01a907a08d00bed4a1a52e35d=1672285800', 'origin': 'https://www.python-spider.com', 'pragma': 'no-cache', 'referer': 'https://www.python-spider.com/challenge/1', # 'safe': '04caa9f364552cfc779f56c2b54184dc', 'sec-ch-ua': '"Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-origin', # 'timestamp': '1672292920', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36', 'x-requested-with': 'XMLHttpRequest' } url = 'https://www.python-spider.com/api/challenge1' sun_num = 0 for page in range(1, 101): form_data = { 'page': str(page), } a = '9622' timestamp, *_ = str(time.time()).split('.') jm_var = a + timestamp var_timp = str(base64.b64encode(jm_var.encode('utf-8')), 'utf-8') md = hashlib.md5(var_timp.encode()) tokens = md.hexdigest() headers['timestamp'] = timestamp headers['safe'] = tokens res = requests.post(headers=headers, url=url, data=form_data).json() state = res.get('state') if state == 'success': datas = res.get('data') for data in datas: value = int(data.get('value')) print(value) sun_num += value print('\033[3;31m第{}页面:{}\033[0m\n'.format(page, sun_num)) print('total:{}'.format(sun_num))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。