Created
August 2, 2023 18:06
-
-
Save jjesusfilho/f0684e01628b02231e34c7359dfc0703 to your computer and use it in GitHub Desktop.
Baixa processos do TJAL pelo nome das partes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tjal_baixar_cpopg_par <- function(consulta = NULL, | |
parametro = NULL, | |
distribuidor = "-1", | |
diretorio = ".") { | |
httr::set_config(httr::config(ssl_verifypeer = FALSE)) | |
url1<-"https://www2.tjal.jus.br/cpopg/search.do?" | |
url2<- "https://www2.tjal.jus.br/cpopg/trocarPagina.do?" | |
if(parametro == "NUMOAB" | parametro == "DOCPARTE"){ | |
consulta <- stringr::str_remove_all(consulta, "\\W") | |
} | |
pb <- progress::progress_bar$new(total = length(consulta)) | |
purrr::pmap(list(x = consulta, y = parametro, z = distribuidor), purrr::possibly(function(x, y, z){ | |
pb$tick() | |
query1 <- | |
list( | |
conversationId = "", | |
#dadosConsulta.localPesquisa.cdLocal = "-1", | |
cbPesquisa = y, | |
dadosConsulta.tipoNuProcesso = "UNIFICADO", | |
dadosConsulta.valorConsulta = x, | |
cdForo = z, | |
uuidCaptcha = "" | |
) | |
resposta <- httr::RETRY(verb="GET",url=url1,query=query1,httr::timeout(30)) | |
max_pag <- resposta |> | |
httr::content() |> | |
xml2::xml_find_first(xpath = "//span[@id='contadorDeProcessos']") |> | |
xml2::xml_text(trim=TRUE) |> | |
stringr::str_extract("\\d+") |> | |
as.numeric() |> | |
(\(x) x/25)() |> | |
ceiling() | |
paginas <- 1:max_pag |> as.character() | |
purrr::walk(paginas,purrr::possibly(~{ | |
arquivo <- file.path(diretorio, paste0("consulta_", x,"_parametro_", y,"_distribuidor_", z,"_pagina_", .x, ".html")) | |
query2 <- | |
list( | |
paginaConsulta = .x, | |
conversationId = "", | |
#dadosConsulta.localPesquisa.cdLocal = "-1", | |
cbPesquisa = y, | |
dadosConsulta.tipoNuProcesso = "UNIFICADO", | |
dadosConsulta.valorConsulta = x, | |
cdForo = z, | |
uuidCaptcha = "" | |
) | |
httr::RETRY("GET", | |
url = url2, query = query2, | |
quiet = TRUE, httr::timeout(2), | |
httr::write_disk(arquivo) | |
) | |
},NULL)) | |
},NULL)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment