猿人学----内部题库第一题

练习平台 第一题代码

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))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值