当前位置:   article > 正文

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

猿人学内部题库

练习平台 第一题代码

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))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/59770
推荐阅读
相关标签
  

闽ICP备14008679号