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)
  • 相关阅读:
    网络流 讲解
    二分图判定 【模板】
    POJ——T3352 Road Construction
    shell脚本编写-自动部署及监控
    万能头文件
    1284 2 3 5 7的倍数(容斥原理)
    1289 大鱼吃小鱼(栈)
    1305 Pairwise Sum and Divide(数学 ,规律)
    博客达人
    Prim算法---最小生成树
  • 原文地址:https://www.cnblogs.com/angdh/p/14142534.html
Copyright © 2011-2022 走看看