def book(s, list_booking): to_book = None for booking in list_booking: if booking['hour'] == '20': to_book = booking break if to_book != None: payload = {'cle': to_book['payload']} rep = s.post( 'https://teleservices.paris.fr/srtm/reservationCreneauReserver.action', data=payload) captcha = s.get('https://teleservices.paris.fr/srtm/ImageCaptcha' ).text.encode('ISO-8859-1') solver = CaptchaSolver('browser') payload['jcaptcha_reponse'] = solver.solve_captcha(captcha) payload['valider'] = 'ENREGISTRER' rep = s.post( 'https://teleservices.paris.fr/srtm/ReservationCreneauValidationForm.action', data=payload) if rep.ok: print 'Book done in %s the %s at %sh' % ( to_book['short'], to_book['date'], to_book['hour']) else: print 'Fail booking' else: print 'No book found'
def setUp(self): self.solver = CaptchaSolver('browser') self.wb_patcher = patch('webbrowser.open') self.mock_wb_open = self.wb_patcher.start() self.raw_input_patcher = patch('captcha_solver.captcha_backend' '.browser.input') self.mock_raw_input = self.raw_input_patcher.start()
def create_group(chat_title): chat_title = "MEOW" + str(chat_title) try: thischat = api.messages.createChat(user_ids=chat_users_list, title=chat_title, v=APIVersion) api.messages.removeChatUser(chat_id=thischat, user_id=334479550, v=APIVersion) except Exception as e: captcha_sid = vk.exceptions.VkAPIError.captcha_sid.__get__(e) captcha_url = vk.exceptions.VkAPIError.captcha_img.__get__(e) if (captcha_sid == None) and (captcha_url == None): time.sleep(3) api.messages.createChat(user_ids=chat_users_list, title=chat_title, v=APIVersion) requests_image(captcha_url) solver = CaptchaSolver("antigate", api_key=antigate_token) raw_data = open("captchaGROUP.jpg", "rb").read() captcha_ready = solver.solve_captcha(raw_data) print(captcha_ready) api.messages.createChat( user_ids=chat_users_list, title=chat_title, v=APIVersion, captcha_sid=captcha_sid, captcha_key=captcha_ready, )
def add_audio(access_token, audio_id, owner_id): global headers response = requests.get( "https://api.vk.com/method/audio.add?access_token=" + access_token + "&audio_id=" + str(audio_id) + "&owner_id=" + str(owner_id) + "&v=5.71", headers=headers, verify=False, ).json() try: print(response["response"]) except: print("****Капча на add_audio****\n" + response["error"]["captcha_img"]) captcha_sid = response["error"]["captcha_sid"] requests_image(response["error"]["captcha_img"]) solver = CaptchaSolver("antigate", api_key=antigate_token) raw_data = open("captcha.jpg", "rb").read() captcha_ready = solver.solve_captcha(raw_data) print(captcha_ready) print("Пробуем..") check = requests.get( "https://api.vk.com/method/audio.add?access_token=" + access_token + "&audio_id=" + str(audio_id) + "&owner_id=" + str(owner_id) + "&v=5.71&captcha_sid=" + captcha_sid + "&captcha_key=" + captcha_ready, headers=headers, verify=False, ).json() if check["response"] != None: print("Все успешно!")
def solve_captcha(self): if not self.captcha_img_el: return captcha_solver = CaptchaSolver('rucaptcha', api_key=RUCAPTCHA_API_KEY) img_path = os.path.join(os.getcwd(), 'captcha.png') self.captcha_img_el.screenshot(img_path) key = captcha_solver.solve_captcha(open(img_path, mode='rb').read()) self.captcha_input_el.send_keys(key)
def captcha_solve(url, key): if key is not None: try: solver = CaptchaSolver('antigate', api_key=key) raw_data = requests.get(url, stream=True).raw.read() key = solver.solve_captcha(raw_data) return key except Exception as e: print("Exception: ", e) return None
def _resolve_captcha(self, image_url): image_bytes = requests.get(image_url).content image = Image.open(BytesIO(image_bytes)) w, h = image.size image = image.crop((0, 0, w, h - 12)) image.save('tmp/captcha.jpg') image_bytes = BytesIO() image.save(image_bytes, format='JPEG') image_bytes = image_bytes.getvalue() solver = CaptchaSolver('rucaptcha', api_key=RutrackerParser.RUCAPTCHA_KEY) result = solver.solve_captcha(image_bytes) return result
def break_captcha(driver): #get captcha image try: img = driver.find_element_by_class_name("captcha__image") src = img.get_attribute('src') urllib.request.urlretrieve(src, "captcha.png") solver = CaptchaSolver('rucaptcha', api_key='bef7004b9dcbbcba502cd826f2bafa49') raw_data = open('captcha.png', 'rb').read() captcha_text = solver.solve_captcha(raw_data) except captcha_solver.error.CaptchaServiceError: driver.find_element_by_class_name("captcha__image").click() break_captcha(driver) return captcha_text
def getRuCaptchaSolver(self, filename): """ :param filename: - Имя файла с фотографией капчи :return: - Вернет саму отгадку капчи """ while True: try: solver = CaptchaSolver('rucaptcha', api_key=self.rucaptcha_key) raw_data = open(filename, 'rb').read() return solver.solve_captcha(raw_data) except: pass
def __solve_captcha(captcha_url: str): """ downloads captcha image and send to 2captcha to solve :param captcha_url: Captcha image url :return: string with captcha solution """ img_name = f'{uuid4()}.jpg' if OutlookAccountCreator.__download_image(captcha_url, img_name): print('Solving Captcha...') solver = CaptchaSolver('2captcha', api_key=API_2_CAPTCHA) raw_data = open(img_name, 'rb').read() solution = solver.solve_captcha(raw_data) os.remove(img_name) print(f"Captcha solved (solution: {solution})...") return solution print('Failed to download captcha image...')
def captcha_handler(captcha): from Settings import RUCAPTCHA_KEY url = captcha.get_url() image_url = requests.get(url) img = image_url.content file = open('tmp.jpg', "wb") file.write(img) file.close() solver = CaptchaSolver('rucaptcha', api_key=RUCAPTCHA_KEY) raw_data = open('tmp.jpg', 'rb').read() return captcha.try_again(solver.solve_captcha(raw_data))
def __init__(self, settings, logger=None): if logger: self.logger = logger else: self.logger = logging.Logger("vk_controller") self.vk_users = [] self.vk_groups = [] self.scope = settings.SCOPE self.group = False self.app_id = settings.APP_ID self.current_user = 0 self.current_token = 0 self.target_client = None self.hold = 0 self.proxies = settings.PROXIES if not self.proxies: self.proxies = [] self.users_data = settings.USERS if not self.users_data: self.users_data = [] self.solver = None if settings.CAPTCHA_KEY and settings.CAPTCHA_SERVER: self.solver = CaptchaSolver(settings.CAPTCHA_SERVER, api_key=settings.CAPTCHA_KEY) loop = asyncio.get_event_loop() if not loop.is_running(): loop.run_until_complete(self.init_vk())
class GuiTestCase(TestCase): def setUp(self): self.solver = CaptchaSolver('gui') self.cw_patcher = patch('captcha_solver.captcha_backend' '.gui.CaptchaWindow') self.mock_cw = self.cw_patcher.start() def tearDown(self): self.cw_patcher.stop() def test_captcha_decoded(self): class MockCW(object): def __init__(self, path, solution): self.solution = solution self.solution.append('decoded_captcha') def main(self): pass self.mock_cw.side_effect = MockCW self.assertEqual(self.solver.solve_captcha(b'image_data'), 'decoded_captcha')
def create_solver(self, **kwargs): config = { 'service_url': self.server.get_url(), 'api_key': 'does not matter', } config.update(kwargs) return CaptchaSolver('antigate', **config)
def resolveNormalCaptcha(self, image_path, retry=5): if not self._api_key: logging.info("No 2captcha API key") return None while retry > 0: try: raw_data = open(image_path, 'rb').read() logging.info("Resolving captcha...") solver = CaptchaSolver('2captcha', api_key=self._api_key) captcha_code = solver.solve_captcha(raw_data) logging.info('Captcha code is:{}'.format(captcha_code)) return captcha_code except print(0): pass return None
def __init__(self, email: str) -> None: self.failed_email_user_id = 0 self.bot_email = email self.queue_from_bot = email self.applicant = Applicant() self.loop = asyncio.get_event_loop() self.current_appeal: Optional[dict] = None self.stop_timer = Timer(self.stop_appeal_sending, self.loop) self.captcha_solver = CaptchaSolver() self.user_captcha_text: Optional[str] = None
def solve_captcha(self, response): if os.environ.get('ANTICAPTCHA_API_KEY'): solver = CaptchaSolver('antigate', api_key=os.environ['ANTICAPTCHA_API_KEY']) else: solver = CaptchaSolver('browser') # Can fetch this a few time and get different randomly-generated captchas to help make a better guess. # See: https://ereg.elections.ca/Telerik.Web.UI.WebResource.axd?type=rca&isc=true&guid=2d918a7f-09cb-4e0e-92e2-125d4ddb156a captcha_path = response.css( '#ctl00_ContentPlaceHolder1_RadCaptcha1_CaptchaImage::attr(src)' ).extract_first() captcha_url = 'https://ereg.elections.ca/{}'.format(captcha_path) jpg_data = urllib.request.urlopen(captcha_url).read() self.crawler.engine.pause() captcha = solver.solve_captcha(jpg_data) self.crawler.engine.unpause() formdata = { '__EVENTTARGET': '', '__EVENTARGUMENT': '', '__VIEWSTATE': response.css('#__VIEWSTATE::attr(value)').extract_first(), '__EVENTVALIDATION': response.css('#__EVENTVALIDATION::attr(value)').extract_first(), 'ctl00$ContentPlaceHolder1$txtCaptcha': captcha, } yield FormRequest.from_response( response, formdata=formdata, formcss='#form1', clickdata={ 'name': 'ctl00$ContentPlaceHolder1$NavButton$BtnNextDelay' }, callback=self.parse_vote_eligibility, )
def _bake_captcha(self, comment_block): import requests from requests.exceptions import InvalidURL from captcha_solver import CaptchaSolver url_image = comment_block.element("img#captcha").src try: get_img = requests.get(url_image, stream=True) except InvalidURL: capthca_url_without_auth = url_image.replace('t:123456%@', '') + '.jpeg' get_img = requests.get(capthca_url_without_auth, stream=True, auth=('t', '123456%')) with open('captcha_rating.jpeg', 'wb') as fd: for chunk in get_img.iter_content(chunk_size=128): fd.write(chunk) solver = CaptchaSolver('antigate', api_key='3d756e5391dd1e1423739217e6579c1a') raw_data = open('captcha_rating.jpeg', 'rb').read() return solver.solve_captcha(raw_data)
def handle_captcha(res): if 'validateCaptcha' not in res.text: return res print '='*78 with open('captcha.html', 'w') as file: file.write(res.content) soup = BeautifulSoup(res.text, 'html.parser') elems = soup.select('form img') fields = { elem.attrs['name']: elem.attrs['value'] for elem in soup.select('form input[type="hidden"]') } print 'Image: ' + elems[0].attrs['src'] img = session.get(elems[0].attrs['src']) with open('captcha.jpg', 'wb') as file: file.write(img.content) solver = CaptchaSolver('browser') fields['field-keywords'] = solver.solve_captcha(img.content).upper() res = session.get( 'https://www.amazon.de/errors/validateCaptcha', params=fields) print '='*78 return handle_captcha(res)
def __init__(self, settings, logger=None): if logger: self.logger = logger else: self.logger = logging.Logger("vk_controller") self.settings = settings self.vk_users = [] self.vk_groups = [] self.scope = settings.SCOPE self.group = False self.app_id = settings.APP_ID self.current_user = 0 self.current_token = 0 self.target_client = None self.hold = 0 self.proxies = settings.PROXIES if not self.proxies: self.proxies = [] if not isinstance(settings.USERS, (list, tuple)) or not settings.USERS: raise ValueError( "You have wrong `USERS` variable in settings. Please, check again." ) for PACK in settings.USERS: if not isinstance(PACK, (list, tuple)) or len(PACK) < 2 or len( PACK) > 3 or PACK[0] not in ("group", "user"): raise ValueError( "You have wrong entity in `USERS` in settings: " + str(PACK)) self.users_data = settings.USERS if not self.users_data: self.users_data = [] self.solver = None if settings.CAPTCHA_KEY and settings.CAPTCHA_SERVER: self.solver = CaptchaSolver(settings.CAPTCHA_SERVER, api_key=settings.CAPTCHA_KEY) loop = asyncio.get_event_loop() if not loop.is_running(): loop.run_until_complete(self.init_vk())
class BrowserTestCase(TestCase): def setUp(self): self.solver = CaptchaSolver('browser') self.wb_patcher = patch('webbrowser.open') self.mock_wb_open = self.wb_patcher.start() self.raw_input_patcher = patch('captcha_solver.backend.browser.input') self.mock_raw_input = self.raw_input_patcher.start() def tearDown(self): self.wb_patcher.stop() self.raw_input_patcher.stop() def test_captcha_decoded(self): self.mock_wb_open.return_value = None self.mock_raw_input.return_value = 'decoded_captcha' self.assertEqual(self.solver.solve_captcha(b'image_data'), 'decoded_captcha')
class BrowserTestCase(TestCase): def setUp(self): self.solver = CaptchaSolver('browser') self.wb_patcher = patch('webbrowser.open') self.mock_wb_open = self.wb_patcher.start() self.raw_input_patcher = patch('captcha_solver.captcha_backend' '.browser.input') self.mock_raw_input = self.raw_input_patcher.start() def tearDown(self): self.wb_patcher.stop() self.raw_input_patcher.stop() def test_captcha_decoded(self): self.mock_wb_open.return_value = None self.mock_raw_input.return_value = 'decoded_captcha' self.assertEqual(self.solver.solve_captcha(b'image_data'), 'decoded_captcha')
class GuiTestCase(TestCase): def setUp(self): self.solver = CaptchaSolver('gui') self.cw_patcher = patch('captcha_solver.backend.gui.CaptchaWindow') self.mock_cw = self.cw_patcher.start() def tearDown(self): self.cw_patcher.stop() def test_captcha_decoded(self): class MockCW(object): def __init__(self, path, solution): self.solution = solution self.solution.append('decoded_captcha') def main(self): pass self.mock_cw.side_effect = MockCW self.assertEqual(self.solver.solve_captcha(b'image_data'), 'decoded_captcha')
def __init__(self, url, f_name, l_name, username, psw, phone, month, day, year, psw_confirm=None, email=None, gender=None, _zip=None, button=None, country=None, captcha_img_alt=None, captcha_input_label=None): self.url = url self.f_name_id = f_name self.l_name_id = l_name self.username_id = username self.psw_id = psw self.phone_id = phone self.month_id = month self.day_id = day self.year_id = year self.psw_confirm_id = psw_confirm self.gender_id = gender self.zip_id = _zip self.button_id = button self.email_id = email self.country_id = country self.captcha_img_alt = captcha_img_alt if captcha_img_alt: self.captcha_solver = CaptchaSolver('rucaptcha', api_key=RUCAPTCHA_API_KEY) self.captcha_input_label = captcha_input_label
driver.find_element_by_id('ap_customer_name').send_keys(name) driver.find_element_by_id('ap_email').send_keys(email) driver.find_element_by_id('ap_password').send_keys(password) driver.find_element_by_id('ap_password_check').send_keys(password) driver.find_element_by_xpath("//*[@id='continue']").click() try: # to bypass the captcha code from captcha_solver import CaptchaSolver from io import BytesIO from PIL import Image element = driver.find_element_by_xpath("//img[@id='auth-captcha-image']") png = driver.get_screenshot_as_png() im = Image.open(BytesIO(png)) im = im.crop((1000,1190,1380,1330)) im.save('captcha.png') solver = CaptchaSolver('antigate', api_key='18ebda48664c28ce6ebc86baa3701579') captcha = open('captcha.png', 'rb').read() captchaCode = solver.solve_captcha(captcha) # solves the captcha puzzle driver.find_element_by_xpath("//*[@id='auth-captcha-guess']").send_keys(captchaCode) driver.find_element_by_id('ap_password').send_keys(password) driver.find_element_by_id('ap_password_check').send_keys(password) driver.find_element_by_xpath("//*[@id='continue']").click() except NoSuchElementException: # unless there isn't a captcha code pass # pass the next page driver.switch_to.window(driver.window_handles[-1]) driver.find_element_by_xpath("//*[@id='payments_widget_add_credit_card_number']").send_keys(creditCard) driver.find_element_by_xpath("//select[@name='expirationMonth']/option[@value='11']").click() driver.find_element_by_xpath("//select[@name='expirationYear']/option[@value='2021']").click() driver.find_element_by_xpath("//*[@id='payments_widget_full_name']").send_keys(name)
from captcha_solver import CaptchaSolver solver=CaptchaSolver('browser') with open('/images/sbi.png','rb') as inp: raw_data=inp.read() print(solver.solve_captcha(raw_data))
def setUp(self): self.solver = CaptchaSolver('gui') self.cw_patcher = patch('captcha_solver.captcha_backend' '.gui.CaptchaWindow') self.mock_cw = self.cw_patcher.start()
class AntigateUrllibTestCase(BaseSolverTestCase): def setup_solver(self): self.solver = CaptchaSolver('antigate', network_backend='urllib', service_url=self.server.get_url(), api_key='does not matter') def test_post_data(self): data = b'foo' res = self.solver.captcha_backend.get_submit_captcha_request_data(data) body = res['post_data']['body'] self.assertTrue(isinstance(body, string_types)) def test_antigate_decoded(self): def handler(): yield b'OK|captcha_id' yield b'OK|decoded_captcha' self.server.response['data'] = handler() self.assertEqual(self.solver.solve_captcha(b'image_data'), 'decoded_captcha') def test_antigate_no_slot_available(self): self.server.response_once['data'] = b'ERROR_NO_SLOT_AVAILABLE' self.assertRaises(SolutionTimeoutError, self.solver.solve_captcha, b'image_data', **NO_DELAY) def test_antigate_zero_balance(self): self.server.response_once['data'] = b'ERROR_ZERO_BALANCE' self.assertRaises(BalanceTooLow, self.solver.solve_captcha, b'image_data') def test_antigate_unknown_error(self): self.server.response_once['data'] = b'UNKNOWN_ERROR' self.assertRaises(CaptchaServiceError, self.solver.solve_captcha, b'image_data') def test_antigate_unknown_code(self): self.server.response_once['code'] = 404 self.assertRaises(CaptchaServiceError, self.solver.solve_captcha, b'image_data') def test_solution_timeout_error(self): def handler(): yield b'OK|captcha_id' yield b'CAPCHA_NOT_READY' self.server.response['data'] = handler() self.assertRaises(SolutionTimeoutError, self.solver.solve_captcha, b'image_data', **NO_DELAY) def test_solution_unknown_error(self): def handler(): yield b'OK|captcha_id' yield b'UNKNOWN_ERROR' self.server.response['data'] = handler() self.assertRaises(CaptchaServiceError, self.solver.solve_captcha, b'image_data', **NO_DELAY) def test_solution_unknown_code(self): def handler(): yield b'OK|captcha_id' self.server.response['data'] = handler() self.assertRaises(CaptchaServiceError, self.solver.solve_captcha, b'image_data', **NO_DELAY)
#br.set_debug_redirects(True) #br.set_debug_responses(True) # Open first page response = br.open(home_url) # Find CAPTCHA URL and download the image file html1 = response.read() page = BeautifulSoup(html1, "lxml") end_img_url = page.findAll("img")[0].attrs["src"][2:] captcha_url = base_img_url + end_img_url br.retrieve(captcha_url, captcha_file) # Manually solve the captcha print "Please enter below the number shown in the viewer window:" solver = CaptchaSolver("browser") with open(captcha_file, "rb") as f: raw_data = f.read() captcha_solution = solver.solve_captcha(raw_data) # Submit form to search for funds br.select_form(nr=0) br.set_all_readonly(False) br.form["txtCNPJNome"] = cnpj br.form["ddlTpFdo"] = 0 br.form["numRandom"] = captcha_solution sleep(1) response = br.submit() # Select fund on search results list
class Copor_TrueSearch(QThread): solver = CaptchaSolver() dirName = 'corporationwiki_truepeople' logcallback = pyqtSignal(object, object) mutex = QMutex() progress_bar = 0 step_plus = 0 try: os.mkdir(dirName) print("Directory ", dirName, " Created ") except FileExistsError: print("Directory ", dirName, " already exists ") def __init__(self, keyword): QThread.__init__(self) self.keyword = keyword # self.logcallback = logcallback self.paused = False self.default_url = "https://www.truepeoplesearch.com/results?name={0}&citystatezip={1}" self.base_url = "https://www.truepeoplesearch.com/results?name={0}&citystatezip={1}&page={2}" def _check_task_paused(self): while self.paused: print('Sleeping') self.sleep(1) def _intialize(self): self.logcallback.emit("#Now making csv file...........................", 2) # Qtcore open(self.dirName + "/" + "{}.csv".format(self.keyword), "wb").close() header = ["Company Name", "Name", "Role", "Address", "Age", "Filling Type", "Status", "State", "Foreign State", "County", "State ID", "Date Filed", "DOS Process", "Phone1", "phone2", "phone3", "phone4", "phone5", "phone6", "phone7", "phone8", "phone9", "phone10", "email1", "email2", "email3", "email4", "email5", "email6", "email7", "email8", "email9", "email10"] with open(self.dirName + "/" + "{}.csv".format(self.keyword), "a", newline="") as f: csv_writer = csv.DictWriter(f, fieldnames=header, lineterminator='\n') csv_writer.writeheader() self.logcallback.emit("#Open chrome browser open now.....", 4) self.path = "driver\\chromedriver.exe" self.driver = Chrome(executable_path=self.path) self.logcallback.emit("### Open Chrome Browser2 now.............", 6) self.driver1 = Chrome(executable_path=self.path) self.logcallback.emit("### Open Chrome Browser3 now.............", 8) self.driver2 = Chrome(executable_path=self.path) self.logcallback.emit("### Open Chrome Browser4 now.............", 10) self.driver3 = Chrome(executable_path=self.path) self.driver.get("https://www.corporationwiki.com/") self.driver.maximize_window() self.driver1.maximize_window() self.driver2.maximize_window() self.driver3.maximize_window() def parse_page(self): item_urls = [] companyNames = [] self._intialize() self._check_task_paused() time.sleep(5) self.logcallback.emit("### First Page Scraping Start.................", 10) driver = self.driver driver1 = self.driver1 driver2 = self.driver2 driver3 = self.driver3 searchKeyword = driver.find_element_by_id("keywords") searchKeyword.send_keys(self.keyword) searchKeyword.send_keys(Keys.ENTER) self._check_task_paused() self.logcallback.emit("#Input key word... and search....", 10) self.progress_bar = 10 time.sleep(5) companyName_xpaths = driver.find_elements_by_xpath("//div[@class='list-group-item']//a[@class='ellipsis']") all_counts = len(companyName_xpaths) self.step_plus = (100 - self.progress_bar) / 6 self.logcallback.emit("Search Results---------------> : {}".format(all_counts), self.progress_bar) for companyName_xpath in companyName_xpaths: # Checking task is paused or not self._check_task_paused() companyName = companyName_xpath.text item_url = companyName_xpath.get_attribute("href") companyNames.append(companyName) item_urls.append(item_url) print("Company Name-----------------> : ", companyName) print("Item URL---------------------> : ", item_url) print(companyNames, item_urls) for companyName, item_url in zip(companyNames, item_urls): self._check_task_paused() name = "" role = "" address = "" age = "" filling_type = "" status = "" state = "" foreign_state = "" county = "" state_id = "" date_filed = "" dos_process = "" self.data = { "company_name": "", "name": "", "role": "", "address": "", "age": "", "filling_type": "", "status": "", "state": "", "foreign_state": "", "county": "", "state_id": "", "date_filed": "", "dos_process": "" } driver.get(item_url) self.progress_bar = self.progress_bar + self.step_plus self.logcallback.emit("Redirect into {}".format(item_url), self.progress_bar) time.sleep(4) name = driver.find_element_by_xpath("//a[@class='ellipsis']").text role = driver.find_element_by_xpath("//div[contains(@class, 'role-label')]").text print("------------------------------------------------------------------------------") for i in range(0, 9): # Checking task is paused or not self._check_task_paused() if str(i) in name: name = name.replace(str(i), "") try: streetAddress = driver.find_element_by_xpath("//span[@itemprop='streetAddress']").text locality = driver.find_element_by_xpath("//span[@itemprop='addressLocality']").text region = driver.find_element_by_xpath("//span[@itemprop='addressRegion']").text postalCode = driver.find_element_by_xpath("//span[@itemprop='postalCode']").text address = streetAddress + " " + locality + " " + region + " " + postalCode background_url = driver.find_element_by_xpath( "//table[@class='list-table']//tbody//tr[1]/td[1]/div/a").get_attribute("href") print("BackgroundUrl-------------------> : ", background_url) # Checking task is paused or not self._check_task_paused() driver.get(background_url) # Checking task is paused or not self._check_task_paused() time.sleep(4) age = driver.find_element_by_class_name("display-age").text except: label_xpaths = driver.find_elements_by_xpath( "(//table[contains(@class, 'table') and contains(@class, 'table-striped') and contains(@class, 'pad-bottom')])[1]/tbody//tr//th") info_xpaths = driver.find_elements_by_xpath( "(//table[contains(@class, 'table') and contains(@class, 'table-striped') and contains(@class, 'pad-bottom')])[1]/tbody//tr//td") for label_xpath, info_xpath in zip(label_xpaths, info_xpaths): # Checking task is paused or not self._check_task_paused() labelTxt = label_xpath.text infoTxt = info_xpath.text if "Filing Type" in labelTxt: filling_type = infoTxt elif "Status" in labelTxt: status = infoTxt elif "State" in labelTxt and "ID" not in labelTxt and "Foreign" not in labelTxt: state = infoTxt elif "Foreign State" in labelTxt: foreign_state = infoTxt elif "County" in labelTxt: county = infoTxt elif "State ID" in labelTxt: state_id = infoTxt elif "Date Filed" in labelTxt: date_filed = infoTxt elif "DOS Process" in labelTxt: dos_process = infoTxt address = county + " " + state + " " + state_id background_url = driver.find_element_by_xpath( "//table[@class='list-table']//tbody//tr[1]/td[1]/div/a").get_attribute("href") print("BackgroundUrl-------------------> : ", background_url) self.progress_bar = self.progress_bar + self.step_plus self.logcallback.emit("Background checking...", self.progress_bar) # Checking task is paused or not self._check_task_paused() driver.get(background_url) self.progress_bar = self.progress_bar + self.step_plus self.logcallback.emit("Redirect into : {}".format(background_url), self.progress_bar) # Checking task is paused or not self._check_task_paused() time.sleep(4) age = driver.find_element_by_class_name("display-age").text self.progress_bar = self.progress_bar + self.step_plus self.data["company_name"] = companyName self.data["name"] = name self.data["role"] = role self.data["address"] = address self.data["age"] = age self.data["filling_type"] = filling_type self.data["status"] = status self.data["state"] = state self.data["foreign_state"] = foreign_state self.data["county"] = county self.data["state_id"] = state_id self.data["date_filed"] = date_filed self.data["dos_process"] = dos_process self.turepeopleSearch(driver1, driver2, driver3, self.data) def turepeopleSearch(self, driver1, driver2, driver3, data): url = self.default_url.format(data["name"], data["address"]) driver1.get(url) self._check_task_paused() try: self.logcallback.emit("### Recaptcha Detecting >>>................", 24) recaptcha = driver1.find_element_by_class_name("g-recaptcha") recaptchaFlag = True self.logcallback.emit("### Recaptcha Detection True...............", 26) except: recaptchaFlag = False self.logcallback.emit("### Recaptcha Detection False..............", 26) if recaptchaFlag == True: self.logcallback.emit("### Recaptcha Solving Now..................", 26) self.solver.solve_captcha_for_url(driver1, driver1.current_url) driver1.find_element_by_xpath('//button').click() self.logcallback.emit("### Recaptcha Solved.......................", 26) try: itemsInfo = driver1.find_element_by_xpath("//html/body/div[2]/div/div[2]/div[3]/div[1]").text totals = int((itemsInfo.split(" "))[0]) page_counts = math.ceil(totals / 11) self.logcallback.emit("### Total Item Accounts....................", 28) next_flag = False self.logcallback.emit("### Total {} PAGE....................".format(page_counts), 20) for page in range(1, page_counts + 1): self._check_task_paused() if page != 1: driver1.get(self.base_url.format(data["name"], data["address"], page)) time.sleep(2) try: self.logcallback.emit("### Recaptcha Detecting >>>................", 31) recaptcha = driver1.find_element_by_class_name("g-recaptcha") recaptchaFlag = True self.logcallback.emit("### Recaptcha Detection True...............", 32) except: recaptchaFlag = False self.logcallback.emit("### Recaptcha Detection False..............", 32) if recaptchaFlag == True: self.logcallback.emit("### Recaptcha Solving Now..................", 34) self.solver.solve_captcha_for_url(driver1, driver1.current_url) self.driver.find_element_by_xpath('//button').click() self.logcallback.emit("### Recaptcha Solved.......................", 36) ownerXpaths = driver1.find_elements_by_xpath( "//div[contains(@class, 'card-summary')]//div[@class='h4']") viewButtons = driver1.find_elements_by_xpath( "//div[contains(@class, 'card-summary')]//div[contains(@class, 'align-self-center')]/a") for ownerXpath, viewButton in zip(ownerXpaths, viewButtons): self._check_task_paused() ownerName = ownerXpath.text flag = self.destinction(ownerName.lower(), self.data["name"].lower()) if flag == 2: self.logcallback.emit("### First Mode.......................", 30) second_url = viewButton.get_attribute('href') driver2.get(second_url) self._check_task_paused() self.parse_owner(driver2.page_source, driver2) next_flag = True break elif flag == 1: self.logcallback.emit("### Second Mode.......................", 30) second_url = viewButton.get_attribute('href') driver3.get(second_url) self._check_task_paused() self.parse_ownerfind(driver3.page_source, driver3, driver2, self.data["name"]) next_flag = True break if next_flag == True: break except: print("continue") def parse_owner(self, htmlstring, driver2): self._check_task_paused() self.logcallback.emit("### GET INFOS.......................", 35) try: self.logcallback.emit("### Recaptcha Detecting >>>................", 36) recaptcha = driver2.find_element_by_class_name("g-recaptcha") recaptchaFlag = True self.logcallback.emit("### Recaptcha Detection True...............", 38) except: recaptchaFlag = False self.logcallback.emit("### Recaptcha Detection False..............", 38) if recaptchaFlag == True: self.logcallback.emit("### Recaptcha Solving Now..................", 40) self.solver.solve_captcha_for_url(driver2, driver2.current_url) driver2.find_element_by_xpath('//button').click() self.logcallback.emit("### Recaptcha Solved.......................", 44) phone_data = { "phone1": "", "phone2": "", "phone3": "", "phone4": "", "phone5": "", "phone6": "", "phone7": "", "phone8": "", "phone9": "", "phone10": "" } email_data = { "email1": "", "email2": "", "email3": "", "email4": "", "email5": "", "email6": "", "email7": "", "email8": "", "email9": "", "email10": "", } with open(self.dirName + "/" + "{}.csv".format(self.keyword), "a", newline="", encoding='utf-8') as f: writer = csv.writer(f) self.logcallback.emit("### Open {}.csv File...............".format(self.keyword), 45) phones = re.findall(r'[(][\d]{3}[)][ ]?[\d]{3}-[\d]{4}', driver2.page_source) emails = re.findall(r'[\w\.-]+@[\w\.-]+', driver2.page_source) for phone in range(1, len(phones) + 1): phone_data["phone{}".format(phone)] = phones[phone - 1] for email in range(1, len(emails) + 1): if 'truepeople' not in emails[email - 1]: email_data["email{}".format(email)] = emails[email - 1] writer.writerow([self.data["company_name"], self.data["name"], self.data["role"], self.data["address"], self.data["age"], self.data["filling_type"], self.data["status"], self.data["state"], self.data["foreign_state"], self.data["county"], self.data["state_id"], self.data["date_filed"], self.data["dos_process"], phone_data["phone1"], phone_data["phone2"], phone_data["phone3"], phone_data["phone4"], phone_data["phone5"], phone_data["phone6"], phone_data["phone7"], phone_data["phone8"], phone_data["phone9"], phone_data["phone10"], email_data["email1"], email_data["email2"], email_data["email3"], email_data["email4"], email_data["email5"], email_data["email6"], email_data["email7"], email_data["email8"], email_data["email9"], email_data["email10"]]) self.logcallback.emit("*****************************End*******************************", 100) def parse_ownerfind(self, htmlstring, driver3, driver2, original_ownerName): try: recaptcha = driver3.find_element_by_class_name("g-recaptcha") recaptchaFlag = True except: recaptchaFlag = False if recaptchaFlag == True: print('Stage2') self.solver.solve_captcha_for_url(driver3, driver3.current_url) driver3.find_element_by_xpath('//button').click() print('Stage2 done') infos = driver3.find_elements_by_xpath("//a[contains(@class, 'link-to-more') and contains(@class, 'olnk')]") for info in infos: relName = info.text rel_array = (relName.lower()).split(" ") ori_arry = (original_ownerName.lower()).split(" ") common = list(set(rel_array).intersection(ori_arry)) if len(common) == 2: owner_url = info.get_attribute("href") print("relName----------------------->", relName, owner_url) driver3.get(owner_url) time.sleep(2) try: itemsInfo = driver3.find_element_by_xpath("//html/body/div[2]/div/div[2]/div[3]/div[1]").text totals = int((itemsInfo.split(" "))[0]) page_counts = math.ceil(totals / 11) print("Total Items Accounts 2----------------------> : ", page_counts) for page in range(1, page_counts + 1): if page != 1: self.driver1.get((owner_url + "&page={}").format(page)) time.sleep(2) ownerXpaths = driver3.find_elements_by_xpath( "//div[contains(@class, 'card-summary')]//div[@class='h4']") viewButtons = driver3.find_elements_by_xpath( "//div[contains(@class, 'card-summary')]//div[contains(@class, 'align-self-center')]/a") for ownerXpath, viewButton in zip(ownerXpaths, viewButtons): ownerName = ownerXpath.text # print(ownerName) flag = self.destinction(ownerName.lower(), original_ownerName.lower()) if flag == 2: second_url = viewButton.get_attribute('href') driver2.get(second_url) self.parse_owner(driver2.page_source, driver2) break except: driver2.get(owner_url) self.parse_owner(driver2.page_source, driver2) break @staticmethod def destinction(ownerName, original_Name): print("OwnerName-----------> : ", ownerName) print("Original_Name-------> : ", original_Name) owner_array = ownerName.split(" ") original_array = original_Name.split(" ") common = list(set(owner_array).intersection(original_array)) if len(common) >= 2: return 2 elif len(common) == 1 and len(common[0]) != 1: return 1 else: return False def run(self): try: self.parse_page() self.driver.close() self.driver.quit() self.driver1.close() self.driver1.quit() self.driver2.close() self.driver2.quit() self.driver3.close() self.driver3.quit() except Exception as e: pass
print('Your userid', userid, 'is not valid') print('Choose another one by login in', entry_url) sys.exit() # extract link to captcha imgs = soup.find_all("img") gif_id = [img['src'] for img in imgs if 'Security' in str(img)][0] gif = 'https://ready.arl.noaa.gov' + gif_id # download captcha, save result = requests.get(gif, stream=True) with open('captcha.png', 'wb') as out_file: shutil.copyfileobj(result.raw, out_file) # Solve captcha solver = CaptchaSolver('browser') raw_data = open('captcha.png', 'rb').read() code = solver.solve_captcha(raw_data) # Get proc number inputs = soup.find_all('input') proc = [inp['value'] for inp in inputs if 'proc' in str(inp)][0] profile = metfile payload2 = make_payload2(metfile, proc, code, userid=userid, year=year, month=month, day=day, hour=hour,
def setup_solver(self): self.solver = CaptchaSolver('antigate', network_backend='urllib', service_url=self.server.get_url(), api_key='does not matter')
from time import sleep from selenium import webdriver from selenium.webdriver.support.ui import Select from selenium.webdriver.chrome.options import Options from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.keys import Keys from captcha_solver import CaptchaSolver solver = CaptchaSolver('2captcha', api_key='金鑰') options = Options() options.binary_location = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" webdriver_path = 'C:\\chromedriver_win32\\chromedriver.exe' #解決使用 AJAX 動態載入資料的 Single Page Application 應用問題 url = 'https://lvr.land.moi.gov.tw/login.action' driver = webdriver.Chrome(executable_path=webdriver_path, options=options) driver.get(url) #1.關閉說明浮動選單 sleep(2) dialog_close = driver.find_element_by_class_name( 'ui-dialog-titlebar-close').click() #2.選不動產買買 sleep(2) land_sale = driver.find_element_by_xpath( '//div[@class="main_menu"]/ul[@class="sale"]/li/a[@id="land"]').click()
def setup_solver(self): self.solver = CaptchaSolver('antigate', network_backend='grab', service_url=self.server.get_url(), api_key='does not matter')
def decode(): solver = CaptchaSolver('browser') with open('test.jpg', 'rb') as inp: raw_data = inp.read() print(solver.solve_captcha(raw_data))
name_now = api.messages.getChat(chat_id=conf_id,v=APIVersion) check = name_now['title'] #Если надо, то меняем название if check != chat_titles[str(i+1)]: try: api.messages.editChat(chat_id=conf_id,title=chat_titles[str(i+1)],v=APIVersion) except Exception as e: captcha_sid=vk.exceptions.VkAPIError.captcha_sid.__get__(e) captcha_url = vk.exceptions.VkAPIError.captcha_img.__get__(e) if (captcha_sid == None) and (captcha_url == None): time.sleep(3) api.messages.editChat(chat_id=conf_id,title=chat_titles[str(i+1)],v=APIVersion) requests_image(captcha_url) solver = CaptchaSolver('antigate', api_key=antigate_token) raw_data = open('captcha.jpg', 'rb').read() captcha_ready = solver.solve_captcha(raw_data) api.messages.editChat(chat_id=conf_id,title=chat_titles[str(i+1)],v=APIVersion,captcha_sid=captcha_sid,captcha_key=captcha_ready) checker = False for i in range(len(response['updates'])): if checker != True: try: message_longpoll = response['updates'][i][5] chat_longpoll = response['updates'][i][3]-2000000000 checker = True except: pass
import logging logger = logging.getLogger(__name__) import json import time import urllib.parse import requests from captcha_solver import CaptchaSolver from django.conf import settings captcha_solver = CaptchaSolver("rucaptcha", api_key=settings.KOCHERGA_RUCAPTCHA_KEY) API_VERSION = "5.81" def api_key(): return settings.KOCHERGA_VK_API_KEY def group_api_key(): return settings.KOCHERGA_VK_GROUP_API_KEY def check_response(r): if "error" in r: raise Exception(r["error"]) if "execute_errors" in r: raise Exception(r["execute_errors"]) if "response" not in r:
def solve_captcha(): solver =CaptchaSolver('browser') imgdata = requests.get("http://xk.fudan.edu.cn/xk/captcha/image.action?d=" + time.time(), cookies=coo,headers=loginheaders) print(imgdata.headers) ans=solver.solve_captcha(imgdata.content) return ans