Skip to content

Commit

Permalink
Update tjsp_ler_movimentacao.R
Browse files Browse the repository at this point in the history
  • Loading branch information
jjesusfilho authored Feb 19, 2024
1 parent aec8330 commit bf38a80
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions R/tjsp_ler_movimentacao.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,52 @@ tjsp_ler_movimentacao <- function (arquivos = NULL, diretorio = ".") {
full.names = TRUE
)
}

purrr::map_dfr(arquivos, purrr::possibly(~{

resposta <- xml2::read_html(.x)

processo <- resposta |>
xml2::xml_find_first("//span[contains(@class,'unj-larger')]") |>
xml2::xml_text() |>
stringr::str_squish() |>
stringr::str_remove_all("[^\\d+\\s]") |>
stringr::str_trim()

cd_processo <- resposta |>
xml2::xml_find_first("//script[contains(text(),'processo.codigo')]") |>
xml2::xml_find_first("//script[contains(text(),'processo.codigo')]|//script[contains(text(),'cdProcesso')]") |>
xml2::xml_text() |>
stringr::str_extract("(?<=processo.codigo=)\\w+")

stringr::str_extract("(?<=(processo.codigo|cdProcesso)=)\\w+")
movs <- resposta |>
xml2::xml_find_first("//table/tbody[@id='tabelaTodasMovimentacoes']") |>
xml2::xml_find_all("./tr")

dt_mov <- movs |>
xml2::xml_find_first("./td[@class='dataMovimentacao']") |>
xml2::xml_find_first("./td[contains(@class,'dataMovimentacao')]") |>
xml2::xml_text(trim = TRUE) |>
lubridate::dmy()

anexo <- movs |>
xml2::xml_find_first("./td[@class='descricaoMovimentacao']/a") |>
anexo <- movs |>
xml2::xml_find_first("./td[contains(@class,'descricaoMovimentacao')]/a") |>
xml2::xml_attr("href")

cd_documento <- anexo |>
stringr::str_extract("(?<=cdDocumento=)\\d+")


recurso_acessado <- anexo |>
stringr::str_extract("(?<=Acessado=).+") |>
URLdecode() |>
stringr::str_replace_all("\\+", " ")

url <- ifelse(is.na(anexo), NA_character_, xml2::url_absolute(anexo,"https://esaj.tjsp.jus.br"))


cd_documento <- anexo |>
stringr::str_extract("(?<=cdDocumento=)\\d+")
recurso_acessado <- anexo |>
stringr::str_extract("(?<=Acessado=).+") |>
URLdecode() |>
stringr::str_replace_all("\\+", " ")
url <- ifelse(is.na(anexo), NA_character_, xml2::url_absolute(anexo,"https://esaj.tjsp.jus.br"))
mov <- movs |>
xml2::xml_find_first("./td[@class='descricaoMovimentacao']") |>
xml2::xml_find_first("./td[contains(@class,'descricaoMovimentacao')]") |>
xml2::xml_text(trim=TRUE)

tibble::tibble(
processo,
cd_processo,
Expand Down

0 comments on commit bf38a80

Please sign in to comment.