示例#1
0
    def get_captcha_key(self):
        print("You must solve a CAPTCHA challenge.")
        print("You will be guided through the steps necessary to complete the "
              "challenge.")
        print("Press enter to start the challenge...")
        input()

        while True:
            try:
                token = get_token(
                    RECAPTCHA_API_KEY,
                    RECAPTCHA_SITE_URL,
                    debug=self.debug,
                )
            except Exception:
                print("\nError encountered while solving the CAPTCHA:\n",
                      file=sys.stderr)
                traceback.print_exc()
                print(file=sys.stderr)
                if not ask_yn("Try another captcha?"):
                    print("CAPTCHA challenge failed.")
                    return None
                continue
            print("Successfully solved the CAPTCHA challenge.")
            return token
    def get_captcha_challenge(self):
        """
            1. Query captcha url with site key
            2. From the result get
                a) the challenge text
                b) the challenge id
            3. Query payload url with site key and cid and get
                c) the captcha image
        """
        headers = {'Referer': self.site_ref, 'User-Agent': self.user_agent}
        r = requests.get(self.captcha2_url, headers=headers)

        # r.raise_for_status()

        # html_content = r.content
        html_content = r.text
        print(html_content)

        print(
            librecaptcha.get_token(self.sitekey, self.site_ref,
                                   librecaptcha.random_user_agent()))

        soup = BeautifulSoup(html_content, 'html.parser')

        try:
            self.captcha2_challenge_text = soup.find(
                "div", {
                    'class': 'rc-imageselect-desc-no-canonical'
                }).text
        except:
            self.captcha2_challenge_text = soup.find(
                "div", {
                    'class': 'rc-imageselect-desc'
                }).text

        self.captcha2_challenge_id = soup.find(
            "div", {
                'class': 'fbc-imageselect-challenge'
            }).find('input')['value']

        # Get captcha image
        headers = {'Referer': self.captcha2_url, 'User-Agent': self.user_agent}
        r = requests.get(self.captcha2_payload_url + '?c=' +
                         self.captcha2_challenge_id + '&k=' + self.sitekey,
                         headers=headers)
        self.captcha2_image = r.content
示例#3
0
 def get_captcha_key(self, *, ask: bool):
     if ask:
         print(messages.MUST_SOLVE_CAPTCHA, end="")
         input()
     while True:
         try:
             token = librecaptcha.get_token(
                 RECAPTCHA_API_KEY, RECAPTCHA_SITE_URL, self.user_agent,
                 gui=librecaptcha.has_gui(), debug=self.debug,
             )
         except Exception:
             stderr("\nError encountered while solving the CAPTCHA:\n")
             traceback.print_exc()
             stderr()
             if not ask_yn("Try another CAPTCHA?"):
                 print("CAPTCHA challenge failed.")
                 return None
             continue
         print("Successfully solved the CAPTCHA challenge.")
         return token
示例#4
0
def get_t2s_token():
    assert T2S_AVAILABLE, "If you want to use the text2speech Google Cloud \n" \
                          "service you need to install the librecaptcha package!"
    return librecaptcha.get_token(T2S_APIKEY, T2S_URL, librecaptcha.random_user_agent(), gui=True, debug=False)