def harvest_tokens_manually(): """ Harvest tokens manually """ print (d_(), s_('Manual Token Harvest'), lb_('Number of tokens harvested: %d' % len(captcha_tokens))) # Run the harvest server # XXX: This threading module is deprecated thread.start_new_thread(harvest_server.run, ()) browser = get_chromedriver(chrome_folder_location='ChromeTokenHarvestFolder', window_size=['640,640']) url = 'http://{0}:{1}{2}'.format(user_config.harvestDomain, 5000, '') # Flask runs on port 5000 by default. while len(captcha_tokens) < user_config.numberOfTokens: browser.get(url) main_window = browser.current_window_handle try: activate_captcha(driver=browser) except: print (d_(), x_('Page Load Failed'), lr_('Falling back to 2captcha')) browser.quit() return check_solution(driver=browser, main_window=main_window) token = get_token(driver=browser, main_window=main_window) if token is not None: if len(captcha_tokens) == 0: start_time = time.time() captcha_tokens.append(token) print (d_(), s_('Token Added')) print (d_(), s_('Manual Token Harvest'), lb_('Number of tokens harvested: %d' % len(captcha_tokens))) current_time = time.time() elapsed_time = current_time - start_time print (d_(), s_('Total Time Elapsed'), lb_(round(elapsed_time, 2), 'seconds')) browser.quit()
def get_token(driver, main_window): """ We parse the token from the page """ token = None driver.switch_to.window(main_window) try: submit = WebDriverWait(driver, user_config.sleeping).until( expected_conditions.presence_of_element_located((By.ID, 'submit'))) submit.click() time.sleep(1) except: print(d_(), x_('Captcha Submit'), lr_('Failed to click submit')) token_element = driver.find_element_by_css_selector('p#token') token = token_element.get_attribute('value') if token is not None: print(d_(), s_('Get Token'), lb_(token)) return token
def check_solution(driver, main_window): """ Check to see if we solved the captcha """ solved = False while not solved: driver.switch_to.window(main_window) try: iframe = driver.find_element_by_css_selector('iframe[src*="api2/anchor"]') except: print (d_(), x_('Check Solution'), lr_('Failed to find checkbox')) return driver.switch_to_frame(iframe) try: driver.find_element_by_xpath('//span[@aria-checked="true"]') print (d_(), s_('Check Solution'), lb_('Solved')) solved = True except: solved = False time.sleep(1) return solved
def print_config(self): """ Print out config for debugging. """ print(d_(), s_('Market Locale'), lb_(self.marketLocale)) print(d_(), s_('Parameters Locale'), lb_(self.parametersLocale)) print(d_(), s_('Market'), lb_(self.market)) print(d_(), s_('Market Domain'), lb_(self.marketDomain)) print(d_(), s_('API Environment'), lb_(self.apiEnv)) print(d_(), s_('Market Client ID'), lb_(self.clientId)) print(d_(), s_('Market Site Key'), lb_(self.sitekey)) print(d_(), s_('Captcha Duplicate'), lb_(self.duplicateField)) print(d_(), s_('Cookie'), lb_(self.cookies)) print(d_(), s_('Preload URL'), lb_(self.preloadURL)) print(d_(), s_('Process Captcha'), lb_(self.processCaptcha)) print(d_(), s_('Use Duplicate'), lb_(self.processCaptchaDuplicate)) print(d_(), s_('Product ID'), lb_(self.masterPid)) print(d_(), s_('Desired Size'), lb_(self.mySizes)) print(d_(), s_('Manual Token Harvest'), lb_(self.manuallyHarvestTokens)) print(d_(), s_('Tokens to Harvest'), lb_(self.numberOfTokens)) print(d_(), s_('Harvest Domain'), lb_(self.harvestDomain)) print(d_(), s_('Sleeping'), lb_(self.sleeping)) print(d_(), s_('Debug'), lb_(self.debug)) print(d_(), s_('External Script URL'), lb_(self.scriptURL)) print(d_(), s_('Pause Between ATC'), lb_(self.pauseBeforeBrowserQuit)) print(d_(), s_('Use Link Injection'), lb_(self.useInjectionMethod))
def get_token_from_2captcha(): session = requests.Session() session.verify = False session.cookies.clear() pageurl = 'http://www.{0}'.format(user_config.marketDomain) print(d_(), s_('pageurl'), lb_(pageurl)) print(d_(), s_('sitekey'), lb_(user_config.sitekey)) while True: data = { 'key': user_config.apikey2captcha, 'action': 'getbalance', 'json': 1, } response = session.get(url='http://2captcha.com/res.php', params=data) if "ERROR_WRONG_USER_KEY" in response.text: print(d_(), x_('Response'), y_(response.text)) sys.exit(exit_code) try: JSON = response.json() except: raise print(d_(), x_('Sleeping'), y_(user_config.sleeping, 'seconds')) time.sleep(user_config.sleeping) continue if JSON['status'] == 1: balance = JSON['request'] print(d_(), s_('Balance'), lb_('${0}'.format(balance))) else: print(d_(), x_('Balance')) CAPTCHAID = None proceed = False while not proceed: data = { 'key': user_config.apikey2captcha, 'method': 'userrecaptcha', 'googlekey': user_config.sitekey, 'proxy': user_config.proxy2Captcha, 'proxytype': 'HTTP', 'pageurl': pageurl, 'json': 1 } response = session.post(url='http://2captcha.com/in.php', data=data) try: JSON = response.json() except: print(d_(), x_('Response'), y_(response.text)) print(d_(), x_('Sleeping'), y_(user_config.sleeping, 'seconds')) time.sleep(user_config.sleeping) continue if JSON['status'] == 1: CAPTCHAID = JSON['request'] proceed = True print(d_(), s_('Captcha ID'), lb_(CAPTCHAID)) else: print(d_(), x_('Response'), y_(response.text)) print(d_(), x_('Sleeping'), y_(user_config.sleeping, 'seconds')) time.sleep(user_config.sleeping) print( d_(), s_('Waiting'), '%d seconds before polling for Captcha response' % user_config.sleeping) time.sleep(user_config.sleeping) TOKEN = None proceed = False while not proceed: data = { 'key': user_config.apikey2captcha, 'action': 'get', 'json': 1, 'id': CAPTCHAID, } response = session.get(url='http://2captcha.com/res.php', params=data) JSON = response.json() if JSON['status'] == 1: TOKEN = JSON['request'] proceed = True print(d_(), s_('Token ID'), lb_(TOKEN)) else: print(d_(), x_('Response'), y_(response.text)) print(d_(), x_('Sleeping'), y_(user_config.sleeping, 'seconds')) time.sleep(user_config.sleeping) data = { 'key': user_config.apikey2captcha, 'action': 'getbalance', 'json': 1, } response = session.get(url='http://2captcha.com/res.php', params=data) JSON = response.json() if JSON['status'] == 1: balance = JSON['request'] print(d_(), s_('Balance'), lb_('${0}'.format(balance))) else: print(d_(), x_('Balance')) if TOKEN is not None: return TOKEN