Created
April 11, 2023 20:49
-
-
Save jjesusfilho/e750f76e141fcfa7294a7d6090f99e45 to your computer and use it in GitHub Desktop.
Esta função está incompleta. Foi criada apenas para exercícios em sala de aula
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
baixar_cjpg <- function(busca, diretorio){ | |
url <- "http://esaj.tjsp.jus.br/cjpg/pesquisar.do" | |
query <- | |
list( | |
conversationId = "", | |
dadosConsulta.pesquisaLivre = busca, | |
tipoNumero = "UNIFICADO", | |
numeroDigitoAnoUnificado = "", | |
foroNumeroUnificado = "", | |
dadosConsulta.nuProcesso = "", | |
dadosConsulta.nuProcessoAntigo = "", | |
classeTreeSelection.values = "", | |
classeTreeSelection.text = "", | |
assuntoTreeSelection.values = "", | |
assuntoTreeSelection.text = "", | |
agenteSelectedEntitiesList = "", | |
contadoragente = "0", | |
contadorMaioragente = "0", | |
cdAgente = "", | |
nmAgente = "", | |
dadosConsulta.dtInicio = "", | |
dadosConsulta.dtFim = "30/03/2023", | |
varasTreeSelection.values = "", | |
varasTreeSelection.text = "", | |
dadosConsulta.ordenacao = "DESC" | |
) | |
conteudo <- httr::GET(url, query = query) |> | |
httr::content() | |
paginas <- conteudo |> | |
xml2::xml_find_first("//td[contains(text(),'Resultados')]") |> | |
xml2::xml_text(trim=T) |> | |
stringr::str_extract("\\d+$") |> | |
as.integer() |> | |
magrittr::divide_by(10) |> | |
ceiling() | |
url <- paste0("http://esaj.tjsp.jus.br/cjpg/trocarDePagina.do?pagina=",.x,"&conversationId=") | |
hora <- Sys.time() |> | |
stringr::str_replace_all("\\D","_") | |
arquivo <- paste0(diretorio,"/cjpg_", hora, "_pagina_", .x,".html") | |
httr::GET(url, httr::write_disk(arquivo, overwrite = T)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment