From 49d135c654df39c24459a58c346abdb54aa959c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20de=20Jesus=20Filho?= Date: Wed, 7 Aug 2024 08:57:54 -0300 Subject: [PATCH] Update tjsp_ler_peticoes_diversas.R --- R/tjsp_ler_peticoes_diversas.R | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/R/tjsp_ler_peticoes_diversas.R b/R/tjsp_ler_peticoes_diversas.R index 2684e8d..ed273c9 100644 --- a/R/tjsp_ler_peticoes_diversas.R +++ b/R/tjsp_ler_peticoes_diversas.R @@ -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)) -} \ No newline at end of file +}