class anticaptcha: gate = None processing = False def __init__(self,agkey): self.gate = AntiGate(agkey) print 'good shit' print 'antigate balance: ' + str(self.gate.balance()) return None def captchasolution(self,error): link = "./captcha_directory/"+str(time.time())+".jpg" urllib.urlretrieve(error.get_url(), link) print 'captcha loaded to directory: ' + link sid = self.gate.send(link) print 'done... lets begin to solution' key = self.gate.get(sid) print 'ok... this code: ' + key os.rename("./captcha_directory/"+key+".jpg") return key def solution(self,error): if self.processing: while self.processing: time.sleep(3) return True,0 else: self.processing = True id = error.try_again(self.captchasolution(error)) self.processing = False return False,id
def error_happens(response, current, params): print "===================ERROR==============================" print response print "===================ERROR END==========================" response = response['error'] if response['error_code'] == 14: #Captcha needed os.popen("curl '%s' > captcha1.jpg" %response['captcha_img']) gate = AntiGate(config.ANTICAPCHA_KEY, auto_run=False) captcha1 = gate.send('captcha1.jpg') captcha = gate.get(captcha1) print captcha time.sleep(90.0) # print "Введи капчу!" # captcha = sys.stdin.readline() # captcha = captcha.split('\n')[0] # print captcha params += [('captcha_sid ', response['captcha_sid']), ('captcha_key', captcha)] method = '' for para in response['request_params']: if para['key'] == 'method': method = para['value'] else: pass r = call_api(method, params, current['token']) print r return r else: print "Дело не в капче!\n", response['error_msg'] return
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')
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')
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')
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')
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')
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')
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'])
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'])
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
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'])
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'])
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
class AG: def __init__(self): self.gate = AntiGate(config.ag_key) self.answer = '' def captcha_solve(self, url): with open('image.jpg', 'wb') as image: image.write(urlopen(url).read()) self.answer = self.gate.send('image.jpg') return self.gate.get(self.answer) def abuse(self): self.gate.abuse()
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'])
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'])
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)
def main_func(self): pyautogui.click(x=771, y=573) is_ok = False while is_ok!=True: if self.status != STOP: sleep(5) pyautogui.moveTo(x=100, y=100) self.driver.save_screenshot('/home/myroslav/reserv/reserv/visareserv/screenshot/screed/1'+'.png') from PIL import Image test_image = "/home/myroslav/reserv/reserv/visareserv/screenshot/screed/1.png" original = Image.open(test_image) box = (569, 89, 982, 596) cropped_example = original.crop(box) cropped_example.save("/home/myroslav/reserv/reserv/visareserv/screenshot/res/1.png", 'png') from antigate import AntiGate gate = AntiGate('AntiGatePass') captcha_id = gate.send("/home/myroslav/reserv/reserv/visareserv/screenshot/res/1.png") result = gate.get(captcha_id) print result if result: all_number = self.get_number_image(result) print "all_number", all_number coordinate = self.get_coordinate(all_number) print "coordinate", coordinate self.click_on_image(coordinate) pyautogui.click(x=954, y=706) pyautogui.moveTo(710, 657, 3, pyautogui.easeInOutQuad) pyautogui.click(x=710, y=657) text = self.driver.find_element_by_xpath('//*[@id="cp1_lblNoDates"]').text print text print self.driver.find_element_by_xpath('//*[@id="cp1_lblNoDatesEmbassyInfo"]').text #We are sorry, but no free slots are available. Try to register later. # [2016-02-19 00:05:09,402: WARNING/Worker-5] 2/19/2016 12:05:12 AM UTC, Ukraine () - Kyjev, Long-term residence permit if "We are sorry" in text: pyautogui.moveTo(685, 439, 3, pyautogui.easeInOutQuad) pyautogui.click(x=685, y=439) sleep(2) obj = DateCheckerBase(company=self, text=text, free_date=None) obj.save() self.main_func() else: is_ok = True obj = DateCheckerBase(company=self, text=text, free_date=None) obj.save()
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
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
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
import time from antigate import AntiGate # AntiCaptcha n = 1 while n<8: start = time.clock() # print AntiGate('888fe7041b163b35255dddafe49bfe6c', "/home/myroslav/reserv/reserv/visareserv/screenshot/res/%d.png" % n) # AntiCaptcha('API-KEY', 'captcha.jpg') print "n = %d" %n gate = AntiGate('888fe7041b163b35255dddafe49bfe6c') # AntiCaptcha('API-KEY') captcha_id = gate.send("/home/myroslav/reserv/reserv/visareserv/screenshot/res/%d.png" % n) print gate.get(captcha_id) end = time.clock() n+=1 interval = end - start print "interval =", interval
from antigate import AntiGate gate = AntiGate('40207091f8f58a38c3bb136b5a8688fe') idsFile = 'ids.txt' solutionsFile = 'solutions.txt' for i in range(1, 2000): captcha_id = gate.send('../samples/' + str(i) + '.png') with open(idsFile, 'a') as f: f.write(str(i) + '\t' + captcha_id + '\n') solved = gate.get(captcha_id) solved = solved.replace("\n", "") solved = solved.replace("\t", "") with open(solutionsFile, 'a') as f: f.write(str(i) + '\t' + solved + '\n')