Пример #1
0
 def captcha_wrapper(self, captcha_image_url):
     if self.anti_key is not None:
         if AntiGate(self.anti_key).balance() > 0:
             response = requests.get(captcha_image_url, stream=True)
             captcha = AntiGate(self.anti_key, response.raw)
             del response
             return str(captcha)
         else:
             logging.error('Anticaptcha error: zero balance')
     else:
         return None
Пример #2
0
 def captcha():
     try:
         img = WebDriverWait(driver, 20).until(
             EC.visibility_of_element_located((By.TAG_NAME, 'img')))
         sleep(1)
         driver.save_screenshot('%i.png' % pid)
         location, size = img.location, img.size
         im = Image.open('%i.png' % pid)  # uses PIL library to open image in memory
         left = location['x']
         top = location['y']
         right = location['x'] + size['width']
         bottom = location['y'] + size['height']
         im = im.crop((left, top, right, bottom))  # defines crop points
         im.save('%i.png' % pid)  # saves new cropped image
         solve = AntiGate(API_KEY, '%i.png' % pid)
         field = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.NAME, 'captcha')))
         field.send_keys(solve.captcha_result)
         field.submit()
         return solve
     except TimeoutException:
         log("Timeout exception")
         keywords.put(row)
         return 1
     except AntiGateError:
         log("Antigate Error")
         return 0
 def captcha():
     try:
         img = WebDriverWait(chrome, 20).until(
             ec.visibility_of_element_located(
                 (By.ID, 'recaptcha_challenge_image')))
         sleep(1)
         chrome.save_screenshot('%i.png' % pid)
         location, size = img.location, img.size
         im = Image.open(
             '%i.png' %
             pid)  # uses PIL library to open image in memory
         left = location['x']
         top = location['y'] - 100
         right = location['x'] + 310
         bottom = location['y'] - 35
         im = im.crop(
             (left, top, right, bottom))  # defines crop points
         im.save('%i.png' % pid)  # saves new cropped image
         solution = AntiGate(API_KEY, '%i.png' % pid)
         field = wait.until(
             ec.visibility_of_element_located(
                 (By.ID, 'recaptcha_response_field')))
         field.send_keys(solution.captcha_result)
         field.submit()
         return solution
     except TimeoutException:
         return 0
     except AntiGateError:
         return 1
Пример #4
0
    def test_manual(self):
        gate = AntiGate(API_KEY, auto_run=False)

        captcha_id = gate.send(IMAGE1)
        self.assertTrue(str(captcha_id).isdigit())

        captcha_value = gate.get(captcha_id)
        self.assertEqual(str(captcha_value), '123')
Пример #5
0
    def test_manual_binary(self):
        gate = AntiGate(API_KEY, auto_run=False)

        captcha_id = gate.send(open(IMAGE1, 'rb').read(), binary=True)
        self.assertTrue(str(captcha_id).isdigit())

        captcha_value = gate.get(captcha_id)
        self.assertEqual(str(captcha_value), '123')
Пример #6
0
    def test_manual_base64(self):
        gate = AntiGate(API_KEY, auto_run=False)
        fp = open(IMAGE1, 'rb')
        captcha_id = gate.send(fp.read())
        self.assertTrue(str(captcha_id).isdigit())
        fp.close()

        captcha_value = gate.get(captcha_id)
        self.assertEqual(str(captcha_value), '123')
Пример #7
0
    def test_multiple(self):
        gate = AntiGate(API_KEY, auto_run=False)
        captcha_id1 = gate.send(IMAGE1)
        captcha_id2 = gate.send(IMAGE2)

        self.assertTrue(str(captcha_id1).isdigit())
        self.assertTrue(str(captcha_id2).isdigit())

        results = gate.get_multi([captcha_id1, captcha_id2])
        self.assertTrue(results == ['123', '456'])
Пример #8
0
def solve_captcha(img):

    while True:
        try:
            gate = AntiGate(key)
            captcha_id = gate.send(img)
            answer = (gate.get(captcha_id))
            return (answer)

        except AntiGateError as error:
            print(error)
            break
Пример #9
0
    def test_multiple_binary(self):
        gate = AntiGate(API_KEY, auto_run=False)
        captcha_id1 = gate.send(open(IMAGE1, 'rb').read(), binary=True)
        captcha_id2 = gate.send(open(IMAGE2, 'rb').read(), binary=True)

        self.assertTrue(str(captcha_id1).isdigit())
        self.assertTrue(str(captcha_id2).isdigit())

        results = gate.get_multi([captcha_id1, captcha_id2])

        #self.assertListEqual(results, ['123', '456'])
        self.assertTrue(results == ['123', '456'])
Пример #10
0
def get_captcha_answer(captcha_url):
    captcha_name = 'captcha.jpg'

    img_data = requests.get(captcha_url).content
    with open(captcha_name, 'wb') as handler:
        handler.write(img_data)

    gate = AntiGate('90f2971a20beee5a508bad796a8790fa')
    captcha_id = gate.send(captcha_name)
    print('Расшифровываем капчу')
    result = gate.get(captcha_id)
    print('Расшифровали капчу: %s' % result)
    return result
Пример #11
0
    def test_multiple_binary(self):
        gate = AntiGate(API_KEY, auto_run=False)
        fp1 = open(IMAGE1, 'rb')
        fp2 = open(IMAGE2, 'rb')
        captcha_id1 = gate.send(fp1.read())
        captcha_id2 = gate.send(fp2.read())
        fp1.close()
        fp2.close()

        self.assertTrue(str(captcha_id1).isdigit())
        self.assertTrue(str(captcha_id2).isdigit())

        results = gate.get_multi([captcha_id1, captcha_id2])
        self.assertTrue(results == ['123', '456'])
Пример #12
0
def captcha_handler(captcha):

    config = get_auth()
    api_key = config.get('antigate', 'api_key')

    cap_img = captcha.get_image()
    print('Разгадываю капчу..')

    gate = AntiGate(api_key)
    captcha_id1 = gate.send(cap_img)
    key = gate.get(captcha_id1)
    print('Разгадал! Тут написанно:', key, 'Ввожу..')

    # Пробуем снова отправить запрос с капчей
    return captcha.try_again(key)
Пример #13
0
 def _decodeCaptchaFile(self):
     captchaImage = self._getCaptchaFile()
     try:
         captchaCode = AntiGate(self._ak,
                                captchaImage,
                                grab_config={
                                    'connect_timeout': 30,
                                    'timeout': 60
                                })
     except Exception, e:
         echo(
             str(e).replace('Errno ', 'E-') + ' Try decode captcha again.',
             'ERROR', self.work_dir)
         self.log('error',
                  inspect.stack()[0][3] + ': ' + str(e))
         self.run()
Пример #14
0
def solve_captcha(image):
    from antigate import AntiGate, AntiGateError

    sent = False
    while not sent:
        try:
            gate = AntiGate('.')
            captcha_id = gate.send(image)
            answer = (gate.get(captcha_id))
            return (answer)

        except AntiGateError as error:
            import _email
            logger.error('<ERROR: %s>' % error)
            _email.send('CAPTCHA', error, " ")
            break
Пример #15
0
    def captcha_send(self, img_bit):
        """
        Принемает картинку ->
        Отправляет её на "анти капчу" ->
        и отдает результат

        :param img_bit: картинка в виде бинарной строки
        :return: результат распознания
        """
        try:
            captcha_gate = AntiGate('35c9e83daa70e28958154736d1621d2e')  # TODO убрать данные
            captcha_id = captcha_gate.send(img_bit)

            captcha = captcha_gate.get(captcha_id)

            logger.info('captcha_gate get: {}'.format(captcha))

            return captcha
        except Exception as err:
            # logger.warning(err)
            return None
Пример #16
0
def deleteLike(xfaves,xtype):
    print('Deleting...')
    getOwner = {
        'post': 'to_id',
        'photo': 'owner_id',
        'video': 'owner_id',
    }
    getId = {
        'post': 'id',
        'photo': 'pid',
        'video': 'vid',
    }
    i = 0
    while i < len(xfaves):
        try:
            api.likes.delete(type=xtype, owner_id=str(xfaves[i][getOwner[xtype]]), item_id=xfaves[i][getId[xtype]])
            time.sleep(0.35)
            i += 1
        except vk.exceptions.VkAPIError as e:
            xcaptcha_sid = e.captcha_sid
            xcaptcha_img = e.captcha_img
            p = requests.get(xcaptcha_img)
            out = open("img.jpg", "wb")
            out.write(p.content)
            out.close()
            xcaptcha_text = str(AntiGate(' ', 'img.jpg')) #Ввести ключ антийгет
            try:
                api.likes.delete(type=xtype, owner_id=str(xfaves[i][getOwner[xtype]]), item_id=xfaves[i][getId[xtype]],
                                 captcha_sid=xcaptcha_sid, captcha_key=xcaptcha_text)
                print("Была решена капча: " + xcaptcha_text + ", все в порядке.")
            except vk.exceptions.VkAPIError as e:
                print("Что-то пошло не так, наверно уменьшил время ожидания?")
                i += 1
        except TypeError:
            print("Что-то пошло не так, типы поломались, пробуем перейти к другой закладке")
            i += 1
Пример #17
0
 def test_balance(self):
     balance = AntiGate(API_KEY).balance()
     self.assertTrue(balance > 0.0)
     self.assertEqual(type(balance), float)
Пример #18
0
 def test_abuse(self):
     gate = AntiGate(API_KEY, IMAGE1)
     if str(gate) != 'qwerty':
         self.assertTrue(gate.abuse())
Пример #19
0
 def test_captcha_config(self):
     config = {'min_len': '3', 'max_len': '4', 'numeric': '1'}
     ag = AntiGate(API_KEY, IMAGE1, send_config=config)
     self.assertEqual(str(ag), '123')
Пример #20
0
 def test_base_binary(self):
     fp = open(IMAGE1, 'rb')
     self.assertEqual(str(AntiGate(API_KEY, fp.read())), '123')
     fp.close()
Пример #21
0
 def test_base64(self):
     fp = open(IMAGE1, 'rb')
     self.assertEqual(str(AntiGate(API_KEY, b64encode(fp.read()))), '123')
     fp.close()
Пример #22
0
 def test_load(self):
     load = AntiGate(API_KEY).load()
     self.assertTrue(len(load) > 0)
     self.assertEqual(type(load), OrderedDict)
     self.assertTrue(load.get('load') is not None)
Пример #23
0
 def test_base(self):
     self.assertEqual(str(AntiGate(API_KEY, IMAGE1)), '123')
Пример #24
0
 def test_load(self):
     self.assertTrue(len(AntiGate(API_KEY).load()) > 0)
Пример #25
0
def get_code(file_name: str) -> str:
    return str(AntiGate(API_KEY, file_name))
Пример #26
0
    def solve(self, driver, limit_log=False):
        self.captcha_type = "recaptcha"  # could also be "text"
        done = False
        """
        Find captcha widget
        """
        found_widget = self.find_widget(driver, limit_log)
        if not found_widget:
            print "didnt find widget"
            return False
        """
        Find captcha popup
        """
        self.find_popup(driver, limit_log)
        """ STRESS TESTING
        test_input = raw_input("continue?")
        if not "y" in test_input:
            return False
        """

        if not limit_log:
            self.pmaster.log("doing challenge")
        done_challenge = False
        done_challenge_tries = 0

        while not done_challenge:
            print "inside while"
            if done_challenge_tries > self.max_try:
                return False
            try:
                """
                Get string challenge, table type and captcha image
                """
                self.challenge_str = driver.find_element_by_class_name(
                    "rc-imageselect-desc-no-canonical").text
                if not limit_log:
                    self.pmaster.log("challenge is '" + self.challenge_str +
                                     "'")
                """
                Gets table object and defines self.type
                """
                self.table = self.get_captcha_table(driver)
                #if self.type == "4x4":
                #if not limit_log:
                #self.pmaster.log("captcha is 4x4, exiting and will start again (if retry is > 1)")
                #return False
                """
                Gets full image to send to 2captcha
                """
                self.image_src = self.get_captcha_image(driver)

                done_challenge = True
            except:
                done_challenge_tries += 1

                # try if captcha is only text response
                try:
                    self.image_src = self.get_captcha_image(driver,
                                                            type="text")
                    self.captcha_type = "text"

                    self.captcha_text_answer = driver.find_element_by_id(
                        'default-response')
                    done_challenge = True
                except:
                    done_challenge_tries += 1
                    print "error: getting challenge image and string"
                    if not limit_log:
                        self.pmaster.log(
                            "error: getting challenge image and string")
                    done_challenge = False
        """
        Save image to /tmp/ folder
        """
        try:
            # save image
            resource = urllib.urlopen(self.image_src)
            self.dir_captcha_image = "tmp/captcha_" + str(
                random.randint(10000, 99999)) + ".jpg"
            output = open(self.dir_captcha_image, "wb")
            output.write(resource.read())
            output.close()

            if self.type == "4x4":
                outfile = self.dir_captcha_image
                size = (600, 600)
                try:
                    im = Image.open(outfile)
                    new_img = im.resize(size)
                    new_img.save(outfile, "JPEG")
                except IOError:
                    print "cannot create 600px img for '%s'" % outfile
                except Exception as e:
                    print "exception creating 600px img for 4x4 catpchas: " + str(
                        e)

        except Exception as e:
            print "Exception ocurred while saving image: " + str(e)
            return False
        """
        Captchas API's access
        """
        #if self.type != "4x4":
        if True:

            try:
                """
                2Captcha API
                """
                if self.captcha_api_service == "2captcha":

                    captcha2upload = CaptchaUpload(self.api_key)
                    self.service = captcha2upload
                    #self.log.warn("2captcha balance = "+captcha2upload.getbalance())

                    self.captcha_result = captcha2upload.solve(
                        self.dir_captcha_image,
                        text=self.challenge_str,
                        type=self.type)
                    print "data returned 2captcha = " + str(
                        self.captcha_result)
                    self.credit_used += 1

                    # couldnt solve
                    if self.captcha_result == 1:
                        self.pmaster.log(
                            "Captcha service couldn't find a solution")
                        self.report_bad_answer()
                        return False
                    else:
                        captcha_answer = True
                """
                Antigate API
                """
                if self.captcha_api_service == "antigate":

                    antigate = AntiGate(str(self.api_key))
                    self.service = antigate
                    #self.log.warn("antigate balance = "+str(antigate.balance()))

                    captcha_id = antigate.send(self.dir_captcha_image)
                    self.captcha_result = antigate.get(captcha_id)
                    print "data returned antigate = " + str(
                        self.captcha_result)
                    self.credit_used += 1

                    captcha_answer = True

                    self.clean_captcha_img()
                """
                ImageTyperz API
                """
                if self.captcha_api_service == "imagetyperz":

                    imagetyperz = ImageTyperz(self.api_user, self.api_pass)
                    self.service = imagetyperz
                    #self.log.warn("imagetyperz balance = "+imagetyperz.get_balance())

                    self.captcha_result = imagetyperz.solve(
                        self.dir_captcha_image)
                    print "data returned by imagetyperz = " + self.captcha_result
                    self.credit_used += 1

                    captcha_answer = True

                    self.clean_captcha_img()

            except AntiGateError:
                print "could not send captcha to Antigate"
                self.pmaster.log("could not send captcha to Antigate")

            except Exception as e:
                print "could not send captcha to" + self.captcha_api_service + "api = " + str(
                    e)
                self.pmaster.log("could not send captcha to " +
                                 self.captcha_api_service + " api = " + str(e))

        else:
            print "not trying 4x4 types...goodbye"
            if not limit_log:
                self.pmaster.log("4x4 captchas not supported")
            return False

        #if self.type != "4x4" and captcha_answer:
        if captcha_answer:
            if not limit_log:
                self.pmaster.log("answering captcha")
            ans = self.answer_captcha(driver, self.captcha_result)
            if ans:
                done = True

        return done
Пример #27
0
 def test_base_binary(self):
     self.assertEqual(
         str(AntiGate(API_KEY, open(IMAGE1, 'rb').read(), binary=True)),
         '123')
Пример #28
0
 def test_balance(self):
     self.assertTrue(AntiGate(API_KEY).balance() > 0)
Пример #29
0
 def test_stats(self):
     stats = AntiGate(API_KEY).stats()
     self.assertTrue(len(stats) > 0)
     self.assertEqual(type(stats), list)
     self.assertEqual(type(stats[0]), OrderedDict)
Пример #30
0
 def test_stats(self):
     self.assertTrue(len(AntiGate(API_KEY).stats()) > 0)