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)
  • 相关阅读:
    java静态工厂实例
    有道云词典+浏览器开PDF文档=科研者外文阅读福利
    高并发实时性网络视频监控项目实战
    Linux环境下天气预报实现
    2019暑假内容复习
    《分布式与云计算》MOOC第三单元课后测试答案
    安装vivado 2016.1时出错
    N皇后问题的一种解法
    window10下基于anaconda安装tensorflow1.14(cpu版本)
    记一次简单的生产环境Mysql调优
  • 原文地址:https://www.cnblogs.com/angdh/p/14142534.html
Copyright © 2011-2022 走看看