• 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)
  • 相关阅读:
    pat甲级1013
    二分查找
    pat甲级1012
    win10 + Ubuntu16.04双系统安装
    win10 U盘重装
    win10蓝牙添加设备无法连接
    Android自定义控件总结
    11.粘性控件
    10.侧拉删除
    9.视差特效、回弹动画、overScrollBy
  • 原文地址:https://www.cnblogs.com/angdh/p/14142534.html
Copyright © 2020-2023  润新知