def download_tj(self,dataIni,dataFim,termo='a'): cursor = cursorConexao() driver = webdriver.Chrome(self.chromedriver) driver.get(self.link_inicial) driver.find_element_by_id(self.pesquisa_livre).send_keys(termo) driver.find_element_by_xpath(self.botao_data_iniXP).send_keys(dataIni) driver.find_element_by_xpath(self.botao_data_fimXP).send_keys(dataFim) driver.find_element_by_xpath('//*[@id="radio-intteor"]').click() driver.find_element_by_xpath(self.botao_pesquisar).click() loop_counter = 0 links_inteiro_teor = driver.find_elements_by_class_name('inteiro-teor') for l in links_inteiro_teor: cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas,l.get_attribute("href"))) driver.find_element_by_xpath(self.botao_proximo_iniXP).click() contador = 0 while True: try: links_inteiro_teor = driver.find_elements_by_class_name('inteiro-teor') for l in links_inteiro_teor: cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas,l.get_attribute("href"))) driver.find_element_by_xpath(self.botao_proximoXP).click() time.sleep(2) except Exception as e: print(e) contador += 1 if contador > 2: break driver.close()
def __init__(self): super().__init__() ssl._create_default_https_context = ssl._create_unverified_context self.link_base = 'http://www.stf.jus.br/portal/processo/verProcessoAndamento.asp?incidente=' self.numero_final = 7000000 # jan 2020 self.numero_inicial = 5428907 # jun 2018 self.cursor = cursorConexao()
def trf5(termo=None): c = crawler_jurisprudencia_trf5() try: for l in range(len(c.lista_anos)): print(c.lista_anos[l],'\n') for m in range(len(c.lista_meses)): for i in range(1,9): try: if termo: c.download_trf5('0'+str(i)+c.lista_meses[m]+c.lista_anos[l],'0'+str(i+1)+c.lista_meses[m]+c.lista_anos[l],termo=termo) else: c.download_trf5('0'+str(i)+c.lista_meses[m]+c.lista_anos[l],'0'+str(i+1)+c.lista_meses[m]+c.lista_anos[l]) except Exception as e: print(e) for i in range(10,27): try: if termo: c.download_trf5(str(i)+c.lista_meses[m]+c.lista_anos[l],str(i+1)+c.lista_meses[m]+c.lista_anos[l],termo=termo) else: c.download_trf5(str(i)+c.lista_meses[m]+c.lista_anos[l],str(i+1)+c.lista_meses[m]+c.lista_anos[l]) except Exception as e: print(e) except Exception as e: print(e) cursor = cursorConexao() cursor.execute('SELECT ementas FROM justica_federal.jurisprudencia_trf5;') dados = cursor.fetchall() for ementa in dados: c.parser_acordaos(ementa[0],cursor)
def download_tj(self, ultima_pag): cursor = cursorConexao() for i in range(ultima_pag): try: time.sleep(5) link = (self.link_inicial % str(i)) driver = webdriver.Chrome(self.chromedriver) driver.get(link) lista_acordaos = driver.find_elements_by_id( 'id_link_abrir_dados_acordao') for i in range(len(lista_acordaos)): lista_acordaos_aux = driver.find_elements_by_id( 'id_link_abrir_dados_acordao') lista_acordaos_aux[i].click() divs_com_rotulo = driver.find_elements_by_class_name( "conteudoComRotulo") links_inteiro_teor = divs_com_rotulo[ -1].find_elements_by_tag_name('span') try: links_inteiro_teor[0].click() except: pass time.sleep(1) driver.find_element_by_id( 'id_comando_voltar_supra').click() driver.close() except Exception as e: print(e)
def sao_paulo_1(termo=None): c = crawler_jurisprudencia_tjsp() cursor = cursorConexao() print('comecei 1a instancia ',c.__class__.__name__) try: for l in range(len(c.lista_anos)): print(c.lista_anos[l],'\n') for m in range(len(c.lista_meses)): try: if termo: if m == 1: c.download_1_inst('01'+c.lista_meses[m]+c.lista_anos[l],'28'+c.lista_meses[m]+c.lista_anos[l], termo=termo) elif m in [0,2,4,6,7,9,11]: c.download_1_inst('01'+c.lista_meses[m]+c.lista_anos[l],'31'+c.lista_meses[m]+c.lista_anos[l], termo=termo) else: c.download_1_inst('01'+c.lista_meses[m]+c.lista_anos[l],'30'+c.lista_meses[m]+c.lista_anos[l], termo=termo) else: if m == 1: c.download_1_inst('01'+c.lista_meses[m]+c.lista_anos[l],'28'+c.lista_meses[m]+c.lista_anos[l]) elif m in [0,2,4,6,7,9,11]: c.download_1_inst('01'+c.lista_meses[m]+c.lista_anos[l],'31'+c.lista_meses[m]+c.lista_anos[l]) else: c.download_1_inst('01'+c.lista_meses[m]+c.lista_anos[l],'30'+c.lista_meses[m]+c.lista_anos[l]) except Exception as e: print(e) except Exception as e: print(e) for i in range(0,1500000,10000): # jun 2018 print(1500000-i) cursor.execute('SELECT sentencas FROM justica_estadual.jurisprudencia_sp_1_inst limit %s,10000;' % str(i)) dados = cursor.fetchall() for dado in dados: c.parse_sp_dados_1_inst(dado[0], cursor)
def amazonas(termo=None): c = crawler_jurisprudencia_tjam() cursor = cursorConexao() print('comecei ',c.__class__.__name__) try: for l in range(3,len(c.lista_anos)): print(c.lista_anos[l],'\n') for m in range(len(c.lista_meses)): try: if termo: if m == 1: crawler_jurisprudencia_tj.download_tj_ESAJ(c,crawler_jurisprudencia_tj,'01'+c.lista_meses[m]+c.lista_anos[l],'28'+c.lista_meses[m]+c.lista_anos[l],termo=termo) elif m in [0,2,4,6,7,9,11]: crawler_jurisprudencia_tj.download_tj_ESAJ(c,crawler_jurisprudencia_tj,'01'+c.lista_meses[m]+c.lista_anos[l],'31'+c.lista_meses[m]+c.lista_anos[l],termo=termo) else: crawler_jurisprudencia_tj.download_tj_ESAJ(c,crawler_jurisprudencia_tj,'01'+c.lista_meses[m]+c.lista_anos[l],'30'+c.lista_meses[m]+c.lista_anos[l],termo=termo) else: if m == 1: crawler_jurisprudencia_tj.download_tj_ESAJ(c,crawler_jurisprudencia_tj,'01'+c.lista_meses[m]+c.lista_anos[l],'28'+c.lista_meses[m]+c.lista_anos[l]) elif m in [0,2,4,6,7,9,11]: crawler_jurisprudencia_tj.download_tj_ESAJ(c,crawler_jurisprudencia_tj,'01'+c.lista_meses[m]+c.lista_anos[l],'31'+c.lista_meses[m]+c.lista_anos[l]) else: crawler_jurisprudencia_tj.download_tj_ESAJ(c,crawler_jurisprudencia_tj,'01'+c.lista_meses[m]+c.lista_anos[l],'30'+c.lista_meses[m]+c.lista_anos[l]) except Exception as e: print(e) except Exception as e: print(e) cursor.execute('SELECT id,ementas from justica_estadual.jurisprudencia_am where id > 29237 limit 10000000;') lista_links = cursor.fetchall() c.download_acordao_am(lista_links) p = pdf_to_text() for arq in os.listdir(path+'/am_2_inst'): c.parser_acordaos(path+'/am_2_inst/'+arq, cursor, p)
def rio_grande_do_sul(termo=None): c = crawler_jurisprudencia_tjrs() cursor = cursorConexao() print('comecei ',c.__class__.__name__) try: for l in range(len(c.lista_anos)): print(c.lista_anos[l],'\n') for m in range(len(c.lista_meses)): for i in range(1,8): try: if termo: c.download_tj('0'+str(i)+c.lista_meses[m]+c.lista_anos[l],'0'+str(i+1)+c.lista_meses[m]+c.lista_anos[l],termo=termo) else: c.download_tj('0'+str(i)+c.lista_meses[m]+c.lista_anos[l],'0'+str(i+1)+c.lista_meses[m]+c.lista_anos[l]) except Exception as e: print(e) for i in range(10,27): try: if termo: c.download_tj(str(i)+c.lista_meses[m]+c.lista_anos[l],str(i+1)+c.lista_meses[m]+c.lista_anos[l],termo=termo) else: c.download_tj(str(i)+c.lista_meses[m]+c.lista_anos[l],str(i+1)+c.lista_meses[m]+c.lista_anos[l]) except Exception as e: print(e) except Exception as e: print(e) cursor.execute('SELECT id, ementas from justica_estadual.jurisprudencia_rs;') links = cursor.fetchall() c.parser_acordaos(links)
def santa_catarina(termo=None): c = crawler_jurisprudencia_tjsc() cursor = cursorConexao() print('comecei ',c.__class__.__name__) for a in c.lista_anos: print(a) for m in range(len(c.lista_meses)): if termo: try: c.download_tj('01/'+c.lista_meses[m]+'/'+a,'14/'+c.lista_meses[m]+'/'+a, termo=termo) except Exception as e: print(e,c.lista_meses[m]) try: c.download_tj('15/'+c.lista_meses[m]+'/'+a,'28/'+c.lista_meses[m]+'/'+a, termo=termo) except Exception as e: print(e,c.lista_meses[m]) else: try: c.download_tj('01/'+c.lista_meses[m]+'/'+a,'14/'+c.lista_meses[m]+'/'+a) except Exception as e: print(e,c.lista_meses[m]) try: c.download_tj('15/'+c.lista_meses[m]+'/'+a,'28/'+c.lista_meses[m]+'/'+a) except Exception as e: print(e,c.lista_meses[m]) cursor.execute('SELECT id,ementas from justica_estadual.jurisprudencia_sc;') lista_links = cursor.fetchall() for i,l in lista_links: c.download_acordao_sc(l, i, cursor) cursor.execute('SELECT texto from justica_estadual.jurisprudencia_sc;') dados = cursor.fetchall() for dado in dados: c.parser_acordaos(dado[0], cursor)
def rio_grande_do_norte(termo=None): c = crawler_jurisprudencia_tjrn() print('comecei ',c.__class__.__name__) try: for l in range(len(c.lista_anos)): print(c.lista_anos[l],'\n') for m in range(len(c.lista_meses)): try: if termo: if m == 1: c.download_tj('01'+c.lista_meses[m]+c.lista_anos[l],'28'+c.lista_meses[m]+c.lista_anos[l],termo=termo) elif m in [0,2,4,6,7,9,11]: c.download_tj('01'+c.lista_meses[m]+c.lista_anos[l],'31'+c.lista_meses[m]+c.lista_anos[l],termo=termo) else: c.download_tj('01'+c.lista_meses[m]+c.lista_anos[l],'30'+c.lista_meses[m]+c.lista_anos[l],termo=termo) else: if m == 1: c.download_tj('01'+c.lista_meses[m]+c.lista_anos[l],'28'+c.lista_meses[m]+c.lista_anos[l]) elif m in [0,2,4,6,7,9,11]: c.download_tj('01'+c.lista_meses[m]+c.lista_anos[l],'31'+c.lista_meses[m]+c.lista_anos[l]) else: c.download_tj('01'+c.lista_meses[m]+c.lista_anos[l],'30'+c.lista_meses[m]+c.lista_anos[l]) except Exception as e: print(e) except Exception as e: print('finalizei o ano com erro ',e) cursor = cursorConexao() cursor.execute('SELECT ementas from justica_estadual.jurisprudencia_rn limit 1000000') dados = cursor.fetchall() for dado in dados: c.parser_acordaos(dado[0], cursor)
def minas_gerais(termo=None): c = crawler_jurisprudencia_tjmg() print('comecei ',c.__class__.__name__) try: for a in c.lista_anos: for m in range(len(c.lista_meses)): if termo: if m == 1: c.download_tj('01'+c.lista_meses[m]+a,'14'+c.lista_meses[m]+a,termo=termo) c.download_tj('15'+c.lista_meses[m]+a,'28'+c.lista_meses[m]+a,termo=termo) elif m in [0,2,4,6,7,9,11]: c.download_tj('01'+c.lista_meses[m]+a,'14'+c.lista_meses[m]+a,termo=termo) c.download_tj('15'+c.lista_meses[m]+a,'31'+c.lista_meses[m]+a,termo=termo) else: c.download_tj('01'+c.lista_meses[m]+a,'14'+c.lista_meses[m]+a,termo=termo) c.download_tj('15'+c.lista_meses[m]+a,'30'+c.lista_meses[m]+a,termo=termo) else: if m == 1: c.download_tj('01'+c.lista_meses[m]+a,'14'+c.lista_meses[m]+a) c.download_tj('15'+c.lista_meses[m]+a,'28'+c.lista_meses[m]+a) elif m in [0,2,4,6,7,9,11]: c.download_tj('01'+c.lista_meses[m]+a,'14'+c.lista_meses[m]+a) c.download_tj('15'+c.lista_meses[m]+a,'31'+c.lista_meses[m]+a) else: c.download_tj('01'+c.lista_meses[m]+a,'14'+c.lista_meses[m]+a) c.download_tj('15'+c.lista_meses[m]+a,'30'+c.lista_meses[m]+a) except Exception as e: print('finalizei com erro ',e) cursor = cursorConexao() cursor.execute('SELECT ementas from justica_estadual.jurisprudencia_mg;') dados = cursor.fetchall() for dado in dados: c.parser_acordaos(dado[0], cursor)
def maranhao(termo=None): c = crawler_jurisprudencia_tjma() cursor = cursorConexao() try: for a in c.lista_anos: for m in range(len(c.lista_meses)): if termo: if m == 1: c.download_tj('01'+c.lista_meses[m]+a,'28'+c.lista_meses[m]+a, termo=termo) elif m in [0,2,4,6,7,9,11]: c.download_tj('01'+c.lista_meses[m]+a,'31'+c.lista_meses[m]+a, termo=termo) else: c.download_tj('01'+c.lista_meses[m]+a,'30'+c.lista_meses[m]+a, termo=termo) else: if m == 1: c.download_tj('01'+c.lista_meses[m]+a,'28'+c.lista_meses[m]+a) elif m in [0,2,4,6,7,9,11]: c.download_tj('01'+c.lista_meses[m]+a,'31'+c.lista_meses[m]+a) else: c.download_tj('01'+c.lista_meses[m]+a,'30'+c.lista_meses[m]+a) except Exception as e: print(e) cursor.execute('SELECT id, ementas from justica_estadual.jurisprudencia_ma;') dados = cursor.fetchall() for id_d, dado in dados: try: c.parser_acordaos(dado, cursor) except Exception as e: print(id_d, e)
def download_1_inst(self,data_ini, data_fim, termo = 'a'): botao_proximo = '//*[@id="resultados"]/table[1]/tbody/tr[1]/td[2]/div/a[6]' botao_proximo_ini = '//*[@id="resultados"]/table[1]/tbody/tr[1]/td[2]/div/a[5]' data_ini_xpath = '//*[@id="iddadosConsulta.dtInicio"]' data_fim_xpath = '//*[@id="iddadosConsulta.dtFim"]' link = 'https://esaj.tjsp.jus.br/cjpg/pesquisar.do' pesquisa_xpath = '//*[@id="iddadosConsulta.pesquisaLivre"]' cursor = cursorConexao() driver = webdriver.Chrome(self.chromedriver) driver.get(link) driver.find_element_by_xpath(pesquisa_xpath).send_keys(termo) driver.find_element_by_xpath(data_ini_xpath).send_keys(data_ini) driver.find_element_by_xpath(data_fim_xpath).send_keys(data_fim) driver.find_element_by_xpath(self.botao_pesquisar).click() time.sleep(1) texto = crawler_jurisprudencia_tj.extrai_texto_html(self,(driver.page_source)).replace('"','') cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas_1_inst,texto)) driver.find_element_by_xpath(botao_proximo_ini).click() time.sleep(1) texto = crawler_jurisprudencia_tj.extrai_texto_html(self,(driver.page_source)).replace('"','') cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas_1_inst,texto)) contador = 3 while contador: try: driver.find_element_by_xpath(botao_proximo).click() time.sleep(2.5) texto = crawler_jurisprudencia_tj.extrai_texto_html(self,(driver.page_source)).replace('"','') cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas_1_inst,texto)) contador = 3 except: time.sleep(2) contador -= 1 driver.close()
def parse_sp_dados_2_inst(self, path_arquivos=path + '/sp_2_inst/'): cursor = cursorConexao() p = pdf_to_text() for arq in os.listdir(path_arquivos): try: if re.search(r'\.pdf', arq): texto = p.convert_pdfminer(path_arquivos + arq).strip().replace( '\\', '').replace('/', '').replace( '"', '') tribunal = 'sp' numero = busca(r'\d{7}\-\d{2}\.\d{4}\.\d\.\d{2}\.\d{4}', texto, ngroup=0) polo_ativo = busca(r'apelante\s*?\:(.*?)\n', texto, args=re.I) polo_passivo = busca(r'apelado\s*?\:(.*?)\n', texto, args=re.I) cursor.execute( 'INSERT INTO jurisprudencia_2_inst.jurisprudencia_2_inst_societario_processos (tribunal, numero, texto_decisao, polo_ativo, polo_passivo) values ("%s","%s","%s","%s","%s");' % (tribunal, numero, texto, polo_ativo, polo_passivo)) except Exception as e: print(arq) print(e)
def download_tj(self, data_inicial='', data_final='', termo='a'): cursor = cursorConexao() driver = webdriver.Chrome(self.chromedriver) driver.get(self.link_inicial) driver.find_element_by_xpath(self.pesquisa_livre).send_keys(termo) driver.find_element_by_xpath(self.data_iniXP).send_keys(data_inicial) driver.find_element_by_xpath(self.data_fimXP).send_keys(data_final) time.sleep(2) driver.find_element_by_xpath(self.botao_pesquisar).click() contador = 0 while True: try: time.sleep(2) texto = crawler_jurisprudencia_tj.extrai_texto_html( self, driver.page_source) print(texto) break # cursor.execute('INSERT INTO justica_federal.jurisprudencia_trf1 (ementas) value("%s")' % texto.replace('"','')) contador = 0 except Exception as e: print(e) time.sleep(3) contador += 1 if contador > 3: driver.close() break
def download_tj(self, termo='a'): cursor = cursorConexao() driver = webdriver.Chrome(self.chromedriver) driver.get(self.link_inicial) driver.find_element_by_xpath(self.pesquisa_livre).send_keys(termo) driver.find_element_by_xpath(self.botao_pesquisar).click() texto = crawler_jurisprudencia_tj.extrai_texto_html( self, (driver.page_source)).replace('"', '') cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas, texto)) driver.find_element_by_xpath(self.botao_proximo_ini).click() contador = 0 while True: try: time.sleep(1) texto = crawler_jurisprudencia_tj.extrai_texto_html( self, (driver.page_source)).replace('"', '') cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas, texto)) driver.find_element_by_xpath(self.botao_proximo).click() contador = 0 except Exception as e: print(e) contador += 1 time.sleep(5) if contador > 3: driver.close() break
def baixarVotos(self, link): pagina = self.baixa_pag(link) if pagina != '': pagina = BeautifulSoup(pagina, 'lxml') validade = pagina.find("div", {"id": "detalheProcesso"}) if validade: jurisprudencia = pagina.find( 'a', href=re.compile(r'.+/jurisprudencia/listarConso.+')) if jurisprudencia: link_jurisprudencia = 'http://www.stf.jus.br/portal' + jurisprudencia[ 'href'][2:] pagina_jurisprudencia = self.baixa_pag(link_jurisprudencia) if pagina_jurisprudencia != '': pagina = BeautifulSoup(pagina_jurisprudencia, 'lxml') link_texto_jurisprudencia = pagina.find( 'a', href=re.compile(r'listarJurisprudencia\.asp\?.+')) if link_texto_jurisprudencia: link_texto = "http://www.stf.jus.br/portal/jurisprudencia/" + link_texto_jurisprudencia[ 'href'] pagina_texto = self.baixa_pag(link_texto) pagina = BeautifulSoup(pagina_texto, 'lxml') div_texto = pagina.find('div', {'id': 'divImpressao'}) if div_texto: texto_final = div_texto.get_text().replace( '\"', '') if texto_final: cursor = cursorConexao() cursor.execute( 'INSERT INTO stf.texto_decisoes (link_pagina, texto_decisao) values("%s","%s");' % (link, texto_final))
def download_tj(self, ano): cursor = cursorConexao() driver = webdriver.Chrome(self.chromedriver) driver.get(self.link_inicial) driver.find_element_by_xpath(self.pesquisa_livreXP).send_keys('ementa') driver.find_element_by_xpath(self.ano_julgamentoXP).send_keys(ano) driver.find_element_by_xpath(self.botao_pesquisarXP).click() driver.find_element_by_xpath(self.link_decisoesXP).click() while True: try: time.sleep(1) links_inteiro_teor = driver.find_elements_by_class_name('botaoLink') for i in range(2,len(links_inteiro_teor)): try: links_inteiro_teor[i].click() driver.switch_to.window(driver.window_handles[-1]) time.sleep(1) texto = crawler_jurisprudencia_tj.extrai_texto_html(self,driver.page_source).replace('"','') cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas,texto)) time.sleep(1) pyautogui.hotkey('ctrl','w') driver.switch_to.window(driver.window_handles[0]) except: driver.switch_to.window(driver.window_handles[0]) driver.find_element_by_xpath(self.botao_proximoXP).click() time.sleep(2) except Exception as e: print(e) break driver.close()
def download_tj(self, termo='acordam'): cursor = cursorConexao() driver = webdriver.Chrome(self.chromedriver) driver.get(self.link_inicial) driver.find_element_by_id(self.pesquisa_livre).send_keys(termo) driver.find_element_by_id(self.botao_pesquisar).click() texto = crawler_jurisprudencia_tj.extrai_texto_html( self, (driver.page_source).replace('"', '')) cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas, texto)) loop_counter = 0 while True: try: driver.find_element_by_xpath(self.botao_proximoXP).clear() driver.find_element_by_xpath(self.botao_proximoXP).send_keys( str(self.contador_paginas)) driver.find_element_by_xpath(self.botao_proximo).click() time.sleep(2) self.contador_paginas += 1 texto = crawler_jurisprudencia_tj.extrai_texto_html( self, (driver.page_source).replace('"', '')) cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas, texto)) except: loop_counter += 1 if loop_counter > 3: break time.sleep(5) driver.execute_script("window.history.go(-1)") driver.close()
def download_tj(self,data_ini,data_fim): crawler_jurisprudencia_tj.delete_audios(self) cursor = cursorConexao() driver = webdriver.Chrome(self.chromedriver) driver.get(self.link_inicial) driver.find_element_by_xpath(self.pesquisa_livre).send_keys('direito') driver.find_element_by_xpath(self.data_julgamento_inicialXP).send_keys(data_ini) driver.find_element_by_xpath(self.data_julgamento_finalXP).send_keys(data_fim) driver.find_element_by_xpath(self.botao_pesquisar).click() time.sleep(5) driver.find_element_by_xpath(self.link_download_captcha).click() time.sleep(5) driver.find_element_by_xpath(self.link_captcha).send_keys(crawler_jurisprudencia_tj.captcha(self)) crawler_jurisprudencia_tj.delete_audios(self) while True: try: time.sleep(2) driver.find_element_by_class_name('linkListaEspelhoAcordaos').click() texto = crawler_jurisprudencia_tj.extrai_texto_html(self,(driver.page_source).replace('"','')) cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas,texto)) driver.find_element_by_xpath(self.botao_proximo_XP).click() except Exception as e: print(e) try: driver.find_element_by_xpath(self.link_download_captcha).click() time.sleep(5) driver.find_element_by_xpath(self.link_captcha).send_keys(crawler_jurisprudencia_tj.captcha(self)) crawler_jurisprudencia_tj.delete_audios(self) time.sleep(5) except: driver.close() return driver.close()
def download_tj(self, termo='processo'): cursor = cursorConexao() driver = webdriver.Chrome(self.chromedriver) driver.get(self.link_inicial) time.sleep(1) driver.find_element_by_xpath(self.pesquisa_livre).send_keys(termo) if input( 'Resolva o captcha do Google e digite um número diferente de zero:\n' ): pass contador_loop = 0 while True: try: time.sleep(1) texto = crawler_jurisprudencia_tj.extrai_texto_html( self, driver.page_source).replace('"', '') cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas, texto)) driver.find_element_by_xpath(self.botao_proximoXP).click() except Exception as e: print(e) time.sleep(2) if contador_loop > 2: break contador_loop += 1 driver.close() time.sleep(1)
def baixar_jurisprudencia_carf(self,termo='a ou não a'): cursor = cursorConexao() driver = webdriver.Chrome(self.chromedriver) driver.get(self.link_base) driver.find_element_by_xpath(self.data_ini_xp).clear() driver.find_element_by_xpath(self.data_ini_xp).send_keys('01/2013') driver.find_element_by_xpath(self.input_pesquisa_xp).send_keys(termo) driver.find_element_by_xpath(self.botao_pesquisar_xp).click() time.sleep(5) while True: try: driver.find_element_by_xpath(self.botao_proximo_xp) break except: time.sleep(1) while True: try: driver.execute_script("document.getElementById('conteudo_principal').style.display='inline-block';") time.sleep(1.5) texto = driver.page_source pag = BeautifulSoup(texto,'html.parser') if len(pag.find_all('div', {'id': re.compile(r'tblJurisprudencia\:\d{,3}\:j_')})): self.parsear_html(texto) else: cursor.execute('insert into jurisprudencia_carf.html_decisoes (html_decisoes) values ("%s")' % (driver.page_source.replace('"',''),)) driver.find_element_by_xpath(self.botao_proximo_xp).click() while driver.page_source == texto: time.sleep(1) except Exception as e: print(e)
def download_tj(self, termo='ementa'): cursor = cursorConexao() driver = webdriver.Chrome(self.chromedriver) driver.get(self.link_inicial) driver.find_element_by_id(self.pesquisa_livre).send_keys(termo) driver.find_element_by_xpath(self.botao_pesquisar).click() time.sleep(1) contador = 0 texto = crawler_jurisprudencia_tj.extrai_texto_html(self,(driver.page_source).replace('"','')) cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas,texto)) driver.find_element_by_xpath(self.botao_proximo_iniXP).click() time.sleep(1) texto = crawler_jurisprudencia_tj.extrai_texto_html(self,(driver.page_source).replace('"','')) cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas,texto)) self.botao_proximo_iniXP = '//*[@id="navigator"]/div[1]/a[6]' driver.find_element_by_xpath(self.botao_proximo_iniXP).click() while True: try: texto = crawler_jurisprudencia_tj.extrai_texto_html(self,(driver.page_source).replace('"','')) cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas,texto)) driver.find_element_by_xpath(self.botao_proximoXP).click() time.sleep(2) except: sucesso = False while not sucesso: try: time.sleep(1) driver.execute_script("window.history.go(-1)") driver.find_element_by_xpath(self.botao_proximoXP).click() sucesso = True except: pass driver.close()
def download_tj(self, data_julg_ini, data_julg_fim, termo='acordam'): cursor = cursorConexao() driver = webdriver.Chrome(self.chromedriver) driver.get(self.link_inicial) driver.find_element_by_xpath(self.pesquisa_livre).send_keys(termo) driver.find_element_by_name( self.data_julgamento_inicial).send_keys(data_julg_ini) driver.find_element_by_name( self.data_julgamento_final).send_keys(data_julg_fim) driver.find_elements_by_name(self.botao_pesquisar)[2].click() texto = crawler_jurisprudencia_tj.extrai_texto_html( self, driver.page_source) tamanho = 5 while True: try: time.sleep(3) links_proximos = driver.find_elements_by_class_name( 'linkQuery') texto = crawler_jurisprudencia_tj.extrai_texto_html( self, driver.page_source) cursor.execute( 'INSERT INTO justica_estadual.jurisprudencia_ma (ementas) value("%s")' % texto.replace('"', '')) try: int(links_proximos[-1].text) driver.close() break except: driver.find_element_by_id('pagination').click() except Exception as e: driver.close() print(e) break
def main(): c = crawler_jurisprudencia_tjba() cursor = cursorConexao() p = pdf_to_text() for arq in os.listdir(path + '/ba_2_inst'): c.parser_acordaos(path + '/ba_2_inst/' + arq, cursor, p)
def topic_modelling_proposicoes(self): cursor = cursorConexao() tp = topicModelling() cursor.execute( 'SELECT ementa FROM governo_federal.proposicoes_legislativas_urg;') textos = [ementa[0] for ementa in cursor.fetchall()] topicos = tp.lda_Model(textos, num_words=30) tp.topic_to_txt(topicos)
def main(): c = crawler_jurisprudencia_carf() # c.baixar_jurisprudencia_carf() cursor = cursorConexao() cursor.execute('select id, html_decisoes FROM jurisprudencia_carf.html_decisoes where id > 41443;') for id_p, html in cursor.fetchall(): c.parse_script(html) print(id_p)
def download_tj(self, data_ini, data_fim): cursor = cursorConexao() driver = webdriver.Chrome(self.chromedriver) driver.get(self.link_inicial) driver.find_element_by_xpath(self.pesquisa_livre).send_keys('processo') driver.find_element_by_xpath(self.data_inicialXP).send_keys(data_ini) driver.find_element_by_xpath( '//*[@id="busca_avancada"]/table[1]/tbody/tr/td[1]/span[1]').click( ) driver.find_element_by_xpath(self.data_finalXP).send_keys(data_fim) driver.find_element_by_xpath( '//*[@id="busca_avancada"]/table[1]/tbody/tr/td[1]/span[1]').click( ) time.sleep(1) driver.find_element_by_xpath(self.botao_pesquisar).click() time.sleep(1) links_inteiro_teor = driver.find_elements_by_partial_link_text('') for l in links_inteiro_teor: try: if re.search(r'html\.do', l.get_attribute('href')): texto = l.get_attribute('href') cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas, texto)) except: pass try: driver.find_element_by_xpath(self.botao_proximo_iniXP).click() except: driver.close() return loop_counter = 0 while True: try: time.sleep(1) links_inteiro_teor = driver.find_elements_by_partial_link_text( '') for l in links_inteiro_teor: try: if re.search(r'html\.do', l.get_attribute('href')): texto = l.get_attribute('href') cursor.execute('INSERT INTO %s value ("%s");' % (self.tabela_colunas, texto)) except: pass try: driver.find_element_by_xpath(self.botao_proximoXP % '9').click() except: try: driver.find_element_by_xpath(self.botao_proximoXP % '8').click() except: driver.find_element_by_xpath(self.botao_proximoXP % '7').click() except Exception as e: driver.close() return driver.close()
def main(): c = crawler_jurisprudencia_tjsc() cursor = cursorConexao() cursor.execute( 'SELECT texto_ementa from justica_estadual.jurisprudencia_sc;') dados = cursor.fetchall() for dado in dados: c.parser_acordaos(dado[0], cursor)
def main(): c = crawler_jurisprudencia_tjac() cursor = cursorConexao() cursor.execute( 'SELECT ementas from justica_estadual.jurisprudencia_ac limit 100000;') dados = cursor.fetchall() for dado in dados: c.parser_acordaos(dado[0], cursor)
def main(): c = crawler_jurisprudencia_tjam() cursor = cursorConexao() # cursor.execute('SELECT id,ementas from justica_estadual.jurisprudencia_am where id > 29237 limit 10000000;') # lista_links = cursor.fetchall() # c.download_acordao_am(lista_links) p = pdf_to_text() for arq in os.listdir(path + '/am_2_inst'): c.parser_acordaos(path + '/am_2_inst/' + arq, cursor, p)