def test_api(): access_token = 'access_token_here' # get access token from: http://www.imagetyperz.com/Forms/ClientHome.aspx ita = ImageTyperzAPI(access_token) # init imagetyperz api obj # check account balance balance = ita.account_balance() # get account balance print('Balance: {}'.format(balance)) # print balance captcha_params = { 'page_url': 'https://your-site.com', 'sitekey': '11111111-1111-1111-1111-111111111111', 's_url': 'https://api.arkoselabs.com', # 'data': '{"a": "b"}', # optional, extra funcaptcha data in JSON format # 'proxy': '12.34.56.78:321', # optional, or 126.45.34.53:123:joe:password # 'user_agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0', # optional } captcha_id = ita.submit_funcaptcha(captcha_params) # submit captcha first, to get ID # check if it's still in progress (waiting to be solved), every 10 seconds print('Waiting for captcha to be solved ...') response = None while not response: # while it's still in progress sleep(10) # sleep for 10 seconds and recheck response = ita.retrieve_response(captcha_id) print('Response: {}'.format(response)) # print response of captcha
def test_api(): access_token = 'access_token_here' # get access token from: http://www.imagetyperz.com/Forms/ClientHome.aspx ita = ImageTyperzAPI(access_token) # init imagetyperz api obj # check account balance balance = ita.account_balance() # get account balance print('Balance: {}'.format(balance)) # print balance captcha_params = { 'domain': 'https://example.com', 'geetestid': '647f5ed2ed8acb4be36784e01556bb71', # 'proxy': '126.45.34.53:345', # or 126.45.34.53:123:joe:password # 'user_agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0' # optional } captcha_id = ita.submit_geetest_v4( captcha_params) # submit captcha first, to get ID # check if it's still in progress (waiting to be solved), every 10 seconds print('Waiting for captcha to be solved ...') response = None while not response: # while it's still in progress sleep(10) # sleep for 10 seconds and recheck response = ita.retrieve_response(captcha_id) print('Response: {}'.format(response)) # print response of captcha
def test_api(): access_token = 'access_token_here' # get access token from: http://www.imagetyperz.com/Forms/ClientHome.aspx ita = ImageTyperzAPI(access_token) # init imagetyperz api obj # check account balance balance = ita.account_balance() # get account balance print('Balance: {}'.format(balance)) # print balance captcha_params = { 'domain' :'https://your-site.com', 'challenge': 'eea8d7d1bd1a933d72a9eda8af6d15d3', 'gt': '1a761081b1114c388092c8e2fd7f58bc', # 'api_server': 'api.geetest.com' # geetest domain - optional # 'proxy': '126.45.34.53:345', # or 126.45.34.53:123:joe:password # 'user_agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0' # optional } captcha_id = ita.submit_geetest(captcha_params) # submit captcha first, to get ID # check if it's still in progress (waiting to be solved), every 10 seconds print('Waiting for captcha to be solved ...') response = None while not response: # while it's still in progress sleep(10) # sleep for 10 seconds and recheck response = ita.retrieve_response(captcha_id) print('Response: {}'.format(response)) # print response of captcha
def test_api(): access_token = 'access_token_here' # get access token from: http://www.imagetyperz.com/Forms/ClientHome.aspx ita = ImageTyperzAPI(access_token) # init imagetyperz api obj # check account balance balance = ita.account_balance() # get account balance print('Balance: {}'.format(balance)) # print balance captcha_params = { 'page_url': 'https://your-site.com', 'sitekey': '8c7062c7-cae6-4e12-96fb-303fbec7fe4f', # 'invisible': '1', # if invisible hcaptcha - optional # 'proxy': '126.45.34.53:345', # or 126.45.34.53:123:joe:password # 'user_agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0', # optional } captcha_id = ita.submit_hcaptcha( captcha_params) # submit captcha first, to get ID # check if it's still in progress (waiting to be solved), every 10 seconds print('Waiting for captcha to be solved ...') response = None while not response: # while it's still in progress sleep(10) # sleep for 10 seconds and recheck response = ita.retrieve_response(captcha_id) print('Response: {}'.format(response)) # print response of captcha
def test_api(): access_token = 'access_token_here' # get access token from: http://www.imagetyperz.com/Forms/ClientHome.aspx ita = ImageTyperzAPI(access_token) # init imagetyperz api obj # check account balance balance = ita.account_balance() # get account balance print('Balance: {}'.format(balance)) # print balance captcha_params = { 'page_url': 'https://tiktok.com', # make sure `s_v_web_id` cookie is present 'cookie_input': 's_v_web_id:verify_kd6243o_fd449FX_FDGG_1x8E_8NiQ_fgrg9FEIJ3f;tt_webid:612465623570154;tt_webid_v2:7679206562717014313;SLARDAR_WEB_ID:d0314f-ce16-5e16-a066-71f19df1545f;', # 'proxy': '126.45.34.53:345', # or 126.45.34.53:123:joe:password # 'user_agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0', # optional } captcha_id = ita.submit_tiktok( captcha_params) # submit captcha first, to get ID # check if it's still in progress (waiting to be solved), every 10 seconds print('Waiting for captcha to be solved ...') response = None while not response: # while it's still in progress sleep(10) # sleep for 10 seconds and recheck response = ita.retrieve_response(captcha_id) print('Response: {}'.format(response)) # print response of captcha
def test_api(): access_token = 'access_token_here' # get access token from: http://www.imagetyperz.com/Forms/ClientHome.aspx ita = ImageTyperzAPI(access_token) # init imagetyperz api obj # check account balance balance = ita.account_balance() # get account balance print('Balance: {}'.format(balance)) # print balance print('Waiting for captcha to be solved ...') # works with URL too, if authenticated using token captcha_id = ita.submit_image('captcha.jpg') # optional parameters for image captcha # captcha_id = ita.solve_captcha('captcha.jpg', is_case_sensitive = False, is_phrase = False, digits_only = False, letters_only = True, is_math = False, min_length = 2, max_length = 10) response = ita.retrieve_response(captcha_id) print('Response: {}'.format(response)) # print response of captcha
def solve_captcha(URL_CAPTCHA, SITEKEY): access_token = CONFIG[ 'CAPTCHA_CREDENTIALS'] # Get the credential token to imagetyperZ ita = ImageTyperzAPI(access_token) # Connect to imagetyperZ API recaptcha_params = { 'page_url': URL_CAPTCHA, 'sitekey': SITEKEY, 'proxy': '126.45.34.53:345', } captcha_id = ita.submit_recaptcha( recaptcha_params) # Creates a task to imagetyperZ while ita.in_progress(): # Wait imagetyperz response time.sleep(2) recaptcha_response = ita.retrieve_recaptcha( captcha_id) # Gets the response return recaptcha_response
def test_api(): access_token = 'access_token_here' # get access token from: http://www.imagetyperz.com/Forms/ClientHome.aspx ita = ImageTyperzAPI(access_token) # init imagetyperz api obj # check account balance balance = ita.account_balance() # get account balance print('Balance: {}'.format(balance)) # print balance captcha_params = { 'page_url': 'https://your-site.com', 'sitekey': '7LrGJmcUABBAALFtIb_FxC0LXm_GwOLyJAfbbUCL', # reCAPTCHA type(s) - optional, defaults to 1 # --------------------------------------------- # 1 - v2 # 2 - invisible # 3 - v3 # 4 - enterprise v2 # 5 - enterprise v3 # # 'type' : 1, # # #'v3_min_score' : .3, # optional # #'v3_action' : 'homepage', # optional # #'proxy': '126.45.34.53:345', # or 126.45.34.53:123:joe:password # #'user_agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0', # optional # #'data-s': 'data-s-value-here' # optional # #'cookie_input': 'a=b;c=d' # optional } captcha_id = ita.submit_recaptcha(captcha_params) # submit captcha first, to get ID # check if it's still in progress (waiting to be solved), every 10 seconds print('Waiting for captcha to be solved ...') response = None while not response: # while it's still in progress sleep(10) # sleep for 10 seconds and recheck response = ita.retrieve_response(captcha_id) print('Response: {}'.format(response)) # print response of captcha
def test_api(): access_token = 'access_token_here' # get access token from: http://www.imagetyperz.com/Forms/ClientHome.aspx ita = ImageTyperzAPI(access_token) # init imagetyperz api obj # legacy way, will get deprecated at some point # ita.set_user_password('your_username', 'your_password') # check account balance # --------------------------- balance = ita.account_balance() # get account balance print('Balance: {}'.format(balance)) # print balance # solve image captcha # -------------------- # works with URL as well, if authenticated with token print('Solving captcha ...') captcha_text = ita.solve_captcha('captcha.jpg') # optional parameters for image captcha # captcha_text = ita.solve_captcha('captcha.jpg', is_case_sensitive = False, is_phrase = False, digits_only = False, letters_only = True, is_math = False, min_length = 2, max_length = 10) print('Captcha text: {}'.format(captcha_text)) # solve recaptcha # check https://github.com/imagetyperz-api/API-docs#submit-recaptcha for more details # ----------------------------------------------------------------------------------------------- recaptcha_params = { 'page_url': 'page_url_here', # add --capy or --hcaptcha at the end, to submit capy or hCaptcha 'sitekey': 'sitekey_here', 'type': 1, # optional, 1 - normal recaptcha, 2 - invisible recaptcha, 3 - v3 recaptcha, default: 1 #'v3_min_score' : .3, # optional #'v3_action' : 'homepage', # optional #'proxy': '126.45.34.53:345', # or 126.45.34.53:123:joe:password #'user_agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0', # optional #'data-s': 'data-s-value-here' # optional } captcha_id = ita.submit_recaptcha( recaptcha_params) # submit captcha first, to get ID # check if it's still in progress (waiting to be solved), every 10 seconds print('Waiting for recaptcha to be solved ...') while ita.in_progress(): # while it's still in progress sleep(10) # sleep for 10 seconds and recheck recaptcha_response = ita.retrieve_recaptcha( captcha_id ) # captcha_id is optional, if not given, will use last captcha id submited print('Recaptcha response: {}'.format( recaptcha_response)) # print google response
from imagetyperzapi3.imagetyperzapi import ImageTyperzAPI import time access_token = '9057BFA6CAAB4EACB6540F53C5948CE1' # get access token from: http://www.imagetyperz.com/Forms/ClientHome.aspx ita = ImageTyperzAPI(access_token) # init imagetyperz api obj balance = ita.account_balance() # get account balance print('Balance: {}'.format(balance)) recaptcha_params = { 'page_url': 'https://www.receita.fazenda.gov.br/PessoaJuridica/CNPJ/cnpjreva/cnpjreva_solicitacao2.asp', 'sitekey': '6LcT2zQUAAAAABRp8qIQR2R0Y2LWYTafR0A8WFbr', 'type': 2, # optional, 1 - normal recaptcha, 2 - invisible recaptcha, 3 - v3 recaptcha, default: 1 'v3_min_score': .3, # optional 'v3_action': 'homepage', # optional 'proxy': '126.45.34.53:345', # or 126.45.34.53:123:joe:password 'user_agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0' # optional } captcha_id = ita.submit_recaptcha(recaptcha_params) # print balance # check if it's still in progress (waiting to be solved), every 10 seconds while ita.in_progress(): # while it's still in progress
def shopify_gen(website, email): # if shopify_check(website) == False: # return "ERROR, NOT A VALID SHOPIFY URL" firstname = names.get_first_name() lastname = names.get_last_name() randomnums = random.randint(100, 2000) email = firstname + lastname + str(randomnums) + email data = { 'form_type': 'create_customer', 'utf8': '', 'customer[first_name]': firstname, 'customer[last_name]': lastname, 'customer[email]': email, 'customer[password]': password, } if website.endswith('/') == False: account_url = website + '/account' challenge_url = website + '/challenge' else: account_url = website + 'account' challenge_url = website + 'challenge' pass session = requests.session() submit_account = session.post(account_url, data=data, headers=headers) if submit_account.url == challenge_url: print('CAPTCHA REQUESTED, PLEASE WAIT...\n') sitekey = '6LeoeSkTAAAAAA9rkZs5oS82l69OEYjKRZAiKdaF' captcha_url = website api_key = captcha_api ita = ImageTyperzAPI(captcha_api) # init imagetyperz api obj recaptcha_params = { 'page_url': captcha_url, 'sitekey': sitekey, 'type': 1 } # optional, 1 - normal recaptcha, 2 - invisible recaptcha, 3 - v3 recaptcha, default: 1 auth_token = find_auth_token(submit_account.text) captcha_id = ita.submit_recaptcha(recaptcha_params) try: while ita.in_progress(): print('waiting for captcha...') sleep(10) except: print("Took too long to solve captcha") return ("Took too long to solve captcha") recaptcha_response = ita.retrieve_recaptcha(captcha_id) print('Recaptcha response: {}'.format(recaptcha_response)) captcha_data = { 'utf-8': '', 'authenticity_token': auth_token, 'g-recaptcha-response': recaptcha_response } submit_captcha = session.post(account_url, data=captcha_data, headers=headers, verify=False) if submit_captcha.status_code == 200 or 302 \ and submit_captcha.url != challenge_url: return email + ':' + password else: return 'ERROR' else: return email + ':' + password
def __init__(self): workbook = xlrd.open_workbook(self.planilha) worksheet = workbook.sheet_by_index(0) imovels = [] # con = Connection('localhost','imob','postgres','P2a3u0l9') keys = [v.value for v in worksheet.row(0)] for row_number in range(worksheet.nrows): if row_number == 0: continue row_data = {} for col_number, cell in enumerate(worksheet.row(row_number)): row_data[keys[col_number]] = str(cell.value).replace('.0', '') # con.insertParametro(row_data, '00000000000000') imovels.append(row_data) quantidade_imovels = len(imovels) logging.info(str(quantidade_imovels) + " Imoveis para processamento") try: self.captcha = ImageTyperzAPI(token.TOKEN) print(self.captcha.account_balance()) options = Options() # options.headless = True driver = webdriver.Firefox(options=options) contador = 0 for imovel in imovels: self.create_file(self.path + "/boletos") try: logging.info('Processando {} {} de {}'.format(imovel, contador, quantidade_imovels)) if self.efetuar_login(driver, imovel): imovel['faturas'] = [] imovel['status'] = 'COM DÉBITO' wait = WebDriverWait(driver, 10) wait.until( cond.element_to_be_clickable((By.XPATH, '//button/span[contains(text()," Imprimir ")]'))) while True: btns_imprimir = driver.find_elements_by_xpath( "//button/span[contains(text(),' Imprimir ')]") aba_atual = driver.window_handles[0] for btn_imprimir in btns_imprimir: try: btn_imprimir.click() if len(driver.find_elements_by_xpath("//*[contains(@id,'cdk-overlay-')]")) >= 1: driver.find_element_by_xpath("//button[text()='Confirmar']").click() wait.until(cond.new_window_is_opened) driver.switch_to.window(driver.window_handles[1]) wait.until(cond.text_to_be_present_in_element( (By.XPATH, '//*[@id="htmlDar"]/div/button/strong'), 'Imprimir')) wait.until(cond.invisibility_of_element_located((By.XPATH, '//*[contains(@class,"mat-progress-spinner-indeterminate-animation")]'))) self.extrair_dados(driver, imovel) except Exception as py_ex: logging.error(py_ex) logging.error(py_ex.args) finally: driver.close() driver.switch_to.window(aba_atual) btn_next = driver.find_element_by_xpath( "//button[contains(@class,'mat-paginator-navigation-next')]") if btn_next.is_enabled(): btn_next.click() else: break except Exception as py_ex: imovel['status'] = 'REPROCESSAR' logging.error(py_ex) logging.error(py_ex.args) logging.info(imovel) contador += 1 except Exception as py_ex: logging.error(py_ex) logging.error(py_ex.args) finally: driver.quit() fildnames = ['codImovel', 'inscricao', 'status'] for imovel in imovels: try: for field in [*imovel['faturas'][0]]: fildnames.append(field) break except: pass try: workbook = xlwt.Workbook() worksheet = workbook.add_sheet(u'Resultado') cabecalhoFatura = ['Nome ou Razão Social', 'CPF/CNPJ', 'Endereço', 'Vencimento', 'Cod. Barras', 'Cod Receita', 'Cota ou Refer', 'Exercício', 'Valor', 'Multa', 'Juros', 'Outros', 'Valor Total', 'Tributo'] cabecalhoImovel = ['codigoImovel', 'numeroContrato', 'inscricao', 'status'] for i, val in enumerate(cabecalhoImovel + cabecalhoFatura): worksheet.write(0, i, val) novaLinha = 1; for imovel in imovels: if ('NUMERO DA INSCRICAO DE IMOVEL INCORRETO' == imovel['status'] or imovel['faturas'] is None): for i, val in enumerate(cabecalhoImovel): worksheet.write(novaLinha, i, imovel[val]) novaLinha += 1 else: for fatura in imovel['faturas']: for i, val in enumerate(cabecalhoImovel): worksheet.write(novaLinha, i, imovel[val]) for i, val in enumerate(cabecalhoFatura): worksheet.write(novaLinha, i + 4, fatura[val]) novaLinha += 1 workbook.save(self.path + '/resultado.xls') except IOError as e: logging.error(e) logging.error(e.args) print("I/O error")
class RoboBrasilia(): path = '/home/files/BRASILIA/{}/{}/'.format(datetime.now().strftime('%d_%m_%y'), datetime.now().strftime('%H%M%S%f')) planilha = '/home/henrique/Planilhas/fazendaBrasilia2.xls' consultar_anos_anteriores = True log = logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%d/%m/%Y %H:%M:%S', filename='brasilia.log', level=logging.INFO) def __init__(self): workbook = xlrd.open_workbook(self.planilha) worksheet = workbook.sheet_by_index(0) imovels = [] # con = Connection('localhost','imob','postgres','P2a3u0l9') keys = [v.value for v in worksheet.row(0)] for row_number in range(worksheet.nrows): if row_number == 0: continue row_data = {} for col_number, cell in enumerate(worksheet.row(row_number)): row_data[keys[col_number]] = str(cell.value).replace('.0', '') # con.insertParametro(row_data, '00000000000000') imovels.append(row_data) quantidade_imovels = len(imovels) logging.info(str(quantidade_imovels) + " Imoveis para processamento") try: self.captcha = ImageTyperzAPI(token.TOKEN) print(self.captcha.account_balance()) options = Options() # options.headless = True driver = webdriver.Firefox(options=options) contador = 0 for imovel in imovels: self.create_file(self.path + "/boletos") try: logging.info('Processando {} {} de {}'.format(imovel, contador, quantidade_imovels)) if self.efetuar_login(driver, imovel): imovel['faturas'] = [] imovel['status'] = 'COM DÉBITO' wait = WebDriverWait(driver, 10) wait.until( cond.element_to_be_clickable((By.XPATH, '//button/span[contains(text()," Imprimir ")]'))) while True: btns_imprimir = driver.find_elements_by_xpath( "//button/span[contains(text(),' Imprimir ')]") aba_atual = driver.window_handles[0] for btn_imprimir in btns_imprimir: try: btn_imprimir.click() if len(driver.find_elements_by_xpath("//*[contains(@id,'cdk-overlay-')]")) >= 1: driver.find_element_by_xpath("//button[text()='Confirmar']").click() wait.until(cond.new_window_is_opened) driver.switch_to.window(driver.window_handles[1]) wait.until(cond.text_to_be_present_in_element( (By.XPATH, '//*[@id="htmlDar"]/div/button/strong'), 'Imprimir')) wait.until(cond.invisibility_of_element_located((By.XPATH, '//*[contains(@class,"mat-progress-spinner-indeterminate-animation")]'))) self.extrair_dados(driver, imovel) except Exception as py_ex: logging.error(py_ex) logging.error(py_ex.args) finally: driver.close() driver.switch_to.window(aba_atual) btn_next = driver.find_element_by_xpath( "//button[contains(@class,'mat-paginator-navigation-next')]") if btn_next.is_enabled(): btn_next.click() else: break except Exception as py_ex: imovel['status'] = 'REPROCESSAR' logging.error(py_ex) logging.error(py_ex.args) logging.info(imovel) contador += 1 except Exception as py_ex: logging.error(py_ex) logging.error(py_ex.args) finally: driver.quit() fildnames = ['codImovel', 'inscricao', 'status'] for imovel in imovels: try: for field in [*imovel['faturas'][0]]: fildnames.append(field) break except: pass try: workbook = xlwt.Workbook() worksheet = workbook.add_sheet(u'Resultado') cabecalhoFatura = ['Nome ou Razão Social', 'CPF/CNPJ', 'Endereço', 'Vencimento', 'Cod. Barras', 'Cod Receita', 'Cota ou Refer', 'Exercício', 'Valor', 'Multa', 'Juros', 'Outros', 'Valor Total', 'Tributo'] cabecalhoImovel = ['codigoImovel', 'numeroContrato', 'inscricao', 'status'] for i, val in enumerate(cabecalhoImovel + cabecalhoFatura): worksheet.write(0, i, val) novaLinha = 1; for imovel in imovels: if ('NUMERO DA INSCRICAO DE IMOVEL INCORRETO' == imovel['status'] or imovel['faturas'] is None): for i, val in enumerate(cabecalhoImovel): worksheet.write(novaLinha, i, imovel[val]) novaLinha += 1 else: for fatura in imovel['faturas']: for i, val in enumerate(cabecalhoImovel): worksheet.write(novaLinha, i, imovel[val]) for i, val in enumerate(cabecalhoFatura): worksheet.write(novaLinha, i + 4, fatura[val]) novaLinha += 1 workbook.save(self.path + '/resultado.xls') except IOError as e: logging.error(e) logging.error(e.args) print("I/O error") def extrair_dados(self, driver, imovel): time.sleep(0.5) fatura = {} text = driver.find_element_by_xpath("//body").text fatura['Cod Receita'] = self.find('Cod Receita (.+?)\\n', text, 1) fatura['Cota ou Refer'] = self.find('Refer. (.+?)\\n', text, 1) fatura['Vencimento'] = self.find('Vencimento. (.+?)\\n', text, 1) fatura['Exercício'] = self.find('Exercício. (.+?)\\n', text, 1) fatura['CPF/CNPJ'] = self.find('CPF/CNPJ (.+?)\\n', text, 1) fatura['Valor'] = self.find('Principal - R\\$ (.+?)\\n', text, 1) fatura['Multa'] = self.find('Multa - R\\$ (.+?)\\n', text, 1) fatura['Juros'] = self.find('Juros - R\\$ (.+?)\\n', text, 1) fatura['Outros'] = self.find('Outros - R\\$ (.+?)\\n', text, 1) fatura['Valor Total'] = self.find('Valor Total - R\\$ (.+?)\\n', text, 1) fatura['Cod. Barras'] = self.find('\\n(.+?)\\n01.CF/DF', text, 1).replace(' ', '') fatura['Nome ou Razão Social'] = self.find('Razão Social\\n(.+?)\\n', text, 1) fatura['Endereço'] = self.find('Endereço\n(.+?)\\n', text, 1) tributos = {} if self.find('VLR IPTU: (.+?)\\n', text, 1) != None: tributos['IPTU'] = self.find('VLR IPTU: (.+?)\\n', text, 1) if self.find('VLR TLP : (.+?)\\n', text, 1) != None: tributos['LIXO'] = self.find('VLR TLP : (.+?)\\n', text, 1) fatura['Tributo'] = '/'.join([*tributos]) file_name = '{}_{}_{}.pdf'.format(imovel['codigoImovel'], imovel['inscricao'], fatura['Cota ou Refer']) file_name = re.sub(r"/", "-", file_name) self.gera_pdf(driver, file_name) imovel['faturas'].append(fatura) return imovel def gera_pdf(self, driver, file_name): img = Image.open(BytesIO(driver.find_element_by_tag_name('body').screenshot_as_png)) rgb = Image.new('RGB', img.size, (255, 255, 255)) rgb.paste(img, mask=img.split()[3]) rgb.save(self.path + "/boletos/" + file_name, "PDF", quality=100) def efetuar_login(self, driver, imovel): driver.get("https://ww1.receita.fazenda.df.gov.br/emissao-segunda-via/iptu") inscricao_input = driver.find_element_by_id('mat-input-0') inscricao_input.send_keys(imovel['inscricao']) if self.consultar_anos_anteriores: driver.find_element_by_id('exercicio').click() driver.find_element_by_id('mat-option-1').click() self.resolve_captcha(driver) consultar_btn = driver.find_element_by_xpath("//button[@color='primary']") consultar_btn.click() time.sleep(3) try: mensagem = driver.find_element_by_xpath('//*[contains(@class ,"alert-info")]|//*[contains(@id ,"mat-error")]').text if 'NAO EXISTEM DEBITOS PARA ESSE IMOVEL' in mensagem: imovel['status'] = 'NÃO POSSUI DÉBITOS' else : imovel['status'] = 'NUMERO DA INSCRICAO DE IMOVEL INCORRETO' return False except: return True def create_file(self, path): if not os.path.isdir(path): os.makedirs(path) print('Pasta criada') def find(self, regex, text, group, flag=0): search = re.search(regex, text, flag) try: return search.group(group) except Exception as e: return None def resolve_captcha(self, driver): data = { 'page_url': 'https://ww1.receita.fazenda.df.gov.br/emissao-segunda-via/iptu', 'sitekey': '6LfqGcIUAAAAAL_iFUaRq21hMxF9-AyZst-UQ9ly', 'type': 2 } captcha_id = self.captcha.submit_recaptcha(data) contador = 0 while self.captcha.in_progress(captcha_id): time.sleep(10) contador += 10 logging.info('{}s Esperando Recaptcha'.format(contador)) recaptcha_response = self.captcha.retrieve_recaptcha(captcha_id) print('Recaptcha response: {}'.format(recaptcha_response)) query = "document.getElementById('recaptcha-token').innerHTML = '{}';".format(recaptcha_response) query2 = "document.getElementById('g-recaptcha-response').innerHTML = '{}';".format(recaptcha_response) driver.execute_script(query2) driver.switch_to.frame(driver.find_element_by_xpath('//iframe')) driver.execute_script(query) driver.find_element_by_xpath("//span[@id='recaptcha-anchor']").click() driver.switch_to.default_content() time.sleep(3)
def resolveCaptcha(img): access_token = '' ita = ImageTyperzAPI(access_token) balance = ita.account_balance() print('Balance: {}'.format(balance)) return ita.solve_captcha(img, case_sensitive=False)