Criei um BOT para fazer login automático no Itaú!
Acho um saco ficar fazendo login nos sites dos bancos, então resolvi criar um script em python para fazer isso automaticamente pra mim!
Requisitos
Debian ou Ubuntu
Entrar no website do Itau, tentar fazer o login, receber um aviso e baixar o warsaw(alguma_coisa).deb
Instale o Warsaw
Instale as dependências que faltam
Baixe e instale o Gecko Driver (firefox ou chrome)
Instale o Python3
Instale o pip para python3
Instale o selenium pelo pip
Precisa do Selenium e do GeckoDriver para funcionar!
Crie um arquivo de configuração chamado credentials.json
{"agencia": "1234", "conta_corrente": "123123", "cpf": "12341234123", "senha_eletronica": "123123" }
E aí vai o código!
from selenium import webdriverfrom selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait as Wait from selenium.webdriver.common.keys import Keys from selenium.webdriver.support import expected_conditions as ec from selenium.common.exceptions import TimeoutException, ElementClickInterceptedException from selenium.webdriver.support.ui import Select import time import datetime from datetime import timedelta from dateutil import rrule def start_local_driver(): profile = webdriver.FirefoxProfile() profile.set_preference("general.useragent.override", "Mozilla/5.0 (X11; FreeBSD OS x86_64) Gecko/20100101 Firefox/60.0") options = webdriver.FirefoxOptions() # Set this to true if you want to hide the browser window options.headless = False return webdriver.Firefox(firefox_profile=profile, options=options) def log_in(driver, account_data): driver.get('https://www.itau.com.br/sobre') driver.set_window_size(1023, 696) while True: try: driver.find_element(By.ID, 'campo_agencia').click() driver.find_element(By.ID, 'campo_agencia').send_keys(account_delata['agencia']) driver.find_element(By.ID, 'campo_conta').click() driver.find_element(By.ID, 'campo_conta').send_keys(account_data['conta_corrente']) Wait(driver, 10).until(ec.element_to_be_clickable((By.CLASS_NAME, 'btnSubmit'))) driver.find_element(By.CLASS_NAME, 'btnSubmit').click() print('Clicking submit button.') print(str(datetime.datetime.now()) + ' - Waiting for new page to be loaded...') Wait(driver, 10).until(ec.text_to_be_present_in_element((By.TAG_NAME, 'h1'), 'Selecione um tipo de identificação')) break except TimeoutException as ex: print('Is taking to long to ') print(ex) while True: try: print(str(datetime.datetime.now()) + ' - CPF page loaded.') print(str(datetime.datetime.now()) + ' - Waiting for CPF field...') Wait(driver, 10).until(ec.element_to_be_clickable((By.ID, 'campoCpf'))) time.sleep(2) print(str(datetime.datetime.now()) + ' - CPF field found.') driver.find_element('id', 'campoCpf').click() driver.find_element('id', 'campoCpf').send_keys(account_data['cpf']) time.sleep(1) Wait(driver, 5).until(ec.element_to_be_clickable((By.ID, 'botao-continuar'))) driver.find_element('id', 'botao-continuar').click() print('Waiting for password-click screen.') Wait(driver, 10).until(ec.text_to_be_present_in_element((By.TAG_NAME, 'h1'), 'Bem-vindo,')) print('Password-click screen loaded.') break except TimeoutException as ex: print('Timeout error!!!!') print(ex) # Página de senha por click # exemplo de campo no teclado: # 2 ou 8 Wait(driver, 10).until(ec.element_to_be_clickable((By.ID, 'senha'))) Wait(driver, 10).until(ec.element_to_be_clickable((By.ID, 'acessar'))) while True: try: time.sleep(3) campo_teclado = driver.find_elements('id', 'campoTeclado') for numero in account_data['senha_eletronica']: for botao_senha in campo_teclado: if numero in botao_senha.text: Wait(driver, 10).until(ec.element_to_be_clickable((By.ID, 'campoTeclado'))) botao_senha.click() break except ElementClickInterceptedException as e: print(e) time.sleep(1) while True: try: Wait(driver, 10).until(ec.element_to_be_clickable((By.ID, 'acessar'))) print('Clicando em "Acessar"') driver.find_element('id', 'acessar').click() break except TimeoutException as e: print(e) while True: try: print('Esperando o radio button basico aparecer') Wait(driver, 10).until(ec.element_to_be_clickable((By.ID, 'rdBasico'))) driver.find_element('id', 'rdBasico').click() Wait(driver, 10).until(ec.element_to_be_clickable((By.ID, 'btn-continuar'))) driver.find_element('id', 'btn-continuar').click() print('Waiting for main menu screen.') Wait(driver, 5).until( ec.text_to_be_present_in_element( (By.LINK_TEXT, 'rede e recebimentos') , 'rede e recebimentos') ) print('Main menu screen detected from Rede e recebimentos menu!') break except ElementClickInterceptedException as e: print(e) time.sleep(1) except TimeoutException as e: print(e)(( _driver = start_local_driver() import json credentials = {} with open('credentials.json', 'r') as credentials_file: credentials = json.load(credentials_file) print(credentials) log_in(_driver, credentials)