zoukankan      html  css  js  c++  java
  • X-AA-Challenge X-AA-Challenge-ID X-AA-Challenge-Result

    reproduce        https://stackoverflow.com/questions/53434555/python-requests-enable-cookies-javascript

    from math import cos, pi, floor
    
    import requests
    
    URL = 'http://www.xxxx'
    
    
    def parse_challenge(page):
        """
        Parse a challenge given by mmi and mavat's web servers, forcing us to solve
        some math stuff and send the result as a header to actually get the page.
        This logic is pretty much copied from https://github.com/R3dy/jigsaw-rails/blob/master/lib/breakbot.rb
        """
        top = page.split('<script>')[1].split('
    ')
        challenge = top[1].split(';')[0].split('=')[1]
        challenge_id = top[2].split(';')[0].split('=')[1]
        return {'challenge': challenge, 'challenge_id': challenge_id, 'challenge_result': get_challenge_answer(challenge)}
    
    
    def get_challenge_answer(challenge):
        """
        Solve the math part of the challenge and get the result
        """
        arr = list(challenge)
        last_digit = int(arr[-1])
        arr.sort()
        min_digit = int(arr[0])
        subvar1 = (2 * int(arr[2])) + int(arr[1])
        subvar2 = str(2 * int(arr[2])) + arr[1]
        power = ((int(arr[0]) * 1) + 2) ** int(arr[1])
        x = (int(challenge) * 3 + subvar1)
        y = cos(pi * subvar1)
        answer = x * y
        answer -= power
        answer += (min_digit - last_digit)
        answer = str(int(floor(answer))) + subvar2
        return answer
    
    
    def main():
        s = requests.Session()
        r = s.get(URL)
    
        if 'X-AA-Challenge' in r.text:
            challenge = parse_challenge(r.text)
            r = s.get(URL, headers={
                'X-AA-Challenge': challenge['challenge'],
                'X-AA-Challenge-ID': challenge['challenge_id'],
                'X-AA-Challenge-Result': challenge['challenge_result']
            })
    
            yum = r.cookies
            r = s.get(URL, cookies=yum)
    
        print(r.content)
  • 相关阅读:
    Windows 7 任务计划程序
    '7z' 不是内部或外部命令,也不是可运行的程序
    [转]国外人气最旺的软件测试网站
    AutoIT查找文件内容并修改保存
    BUG 太少
    excel表格数据导入sqlserver数据库
    RoR常见问题
    [转]漫画:程序员的一生
    [转]RubyInstaller: Getting Started with Rails and SQLite3
    [转]C#多线程学习(一) 多线程的相关概念
  • 原文地址:https://www.cnblogs.com/angdh/p/14142534.html
Copyright © 2011-2022 走看看