def search_sinistro(driver): try: driver.switch_to.default_content() except TimeoutException as e: socket_windev.client_socket('TIM') exit() for k, e in ELEMENTS_SEARCH.items(): ELEMENTS_SEARCH[k] = find_element.find_element(driver, k, "NAME")
def main(): database_management.main() with webdriver.Chrome() as driver: driver.set_page_load_timeout(30) porto_login.login(driver) porto_login_gerenciador.find_switch_click(driver) porto_scraper.main(driver) socket_windev.client_socket('FIN') database_management.fecha_conexao() input("PROCESSO FINALIZADO COM SUCESSO.\rPRESSIONE QUALQUER TECLA PARA FECHAR.")
def main(driver): linha = 0 cliente = {} driver.switch_to.window(driver.window_handles[-1]) qtd = database_management.count_cliente() socket_windev.client_socket('QTD|{}'.format(qtd)) res = database_management.select_cliente() for row in res.fetchall(): linha += 1 print("{} - Capturando sinistro {} ano {}".format(linha, row[0], row[1])) search_sinistro(driver) query_sinistro(driver, row[0], row[1]) if search_dossie(driver, row[0]): scrap_dados(row[0], row[1], driver) socket_windev.client_socket('ACK') database_management.update_cliente_exportado(row[0], row[1])
def login(driver): res = database_management.usuario_senha() url = res[2] ELEMENTS["webusrcod"] = res[0] ELEMENTS["webusrshn"] = res[1] try: driver.get(url) except TimeoutException as e: socket_windev.client_socket('TIM') exit() #Troca para o Iframe iframe = find_element.find_element(driver, "login", "NAME") driver.switch_to.frame(iframe) for e, t in ELEMENTS.items(): element = find_element.find_element(driver, e, "NAME") send_keys(element, t) driver.switch_to.default_content()
def find_element(driver, element, search): time.sleep(0.5) if search == "NAME": try: element = driver.find_element(By.NAME, element) except NoSuchElementException as e: socket_windev.client_socket('ERR') elif search == "XPATH": try: element = driver.find_element(By.XPATH, element) except NoSuchElementException as e: socket_windev.client_socket('ERR') elif search == "ID": try: element = driver.find_element(By.ID, element) except NoSuchElementException as e: socket_windev.client_socket('ERR') else: try: element = driver.find_element(By.CLASS_NAME, element) except NoSuchElementException as e: socket_windev.client_socket('ERR') return element