Skip to content

Commit

Permalink
Update tjsp_ler_peticoes_diversas.R
Browse files Browse the repository at this point in the history
  • Loading branch information
jjesusfilho authored Aug 7, 2024
1 parent 974c8f4 commit 49d135c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions R/tjsp_ler_peticoes_diversas.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,29 @@ tjsp_ler_peticoes_diversas <- function(arquivos = NULL,diretorio = ".") {
purrr::map_dfr(arquivos, purrr::possibly(~{


pb$tick()
doc <- xml2::read_html(.x)

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

processo <- stringr::str_extract(.x, "\\d{20}")
cd_processo <- doc |>
xml2::xml_find_first("//a[contains(@href,'processo.codigo')]/@href|//form[contains(@action,'processo.codigo')]/@action") |>
xml2::xml_text() |>
stringr::str_extract("(?<=processo.codigo=)\\w+")



xml2::read_html(.x) |>
doc |>
xml2::xml_find_all(xpath = "//div/h2[contains(text(),'Peti\u00E7\u00F5es diversas')]/../following-sibling::table[1]/tbody/tr") |>
xml2::xml_text() |>
stringr::str_trim() |>
stringr::str_split("\n\\s+") |>
purrr::map_dfr(stats::setNames, c("data","tipo")) |>
dplyr::mutate(data = lubridate::dmy(data)) |>
tibble::add_column(processo = processo, .before = 1)
tibble::add_column(processo = processo, cd_processo = cd_processo, .before = 1)

}, otherwise = NULL))
}
}

0 comments on commit 49d135c

Please sign in to comment.