The esaj package has two very useful functions for downloading lawsuits filed in Brazilian Justice Courts (Tribunais de Justiça). The only arguments you have to provide to them are the lawsuit’s unique number and the directory where to save the downloaded file.

These two functions are called download_cpopg() and download_cposg(). The first one works for first degree lawsuits, while the second one works for second degree lawsuits; despite this superficial difference, both download lawsuits as HTMLs and return the paths to the downloaded files in the exact same way.

It’s important to note that you shouldn’t provide a filename to the path argument. You can pass more than one lawsuit ID to these functions, meaning that path has to contain the directory where all the files should be downloaded to.

Basic usage

To download a first degree lawsuits, simply provide the lawsuit’s unique number (ID) and the path to the directory where the file should be saved. The ID doesn’t necessarily have to have all divisor marks, but I’ll leave them here for clarity purposes anyway.

download_cpopg("0123479-07.2012.8.26.0100", "~/Desktop/")
#> [1] "/Users/user/Desktop/01234790720128260100.html"

If you want to download more than one lawsuit, provide all IDs in a character vector and the function will take care of the rest. All lawsuits will be independently downloaded to the provided directory as if the fuction had been called once for each ID.

ids <- c(
  "0123479-07.2012.8.26.0100",
  "0552486-62.2015.8.05.0001",
  "0303349-44.2014.8.24.0020")
download_cpopg(ids, "~/Desktop/")
#> [1] "/Users/user/Desktop/01234790720128260100.html"
#> [2] "/Users/user/Desktop/05524866220158050001.html"
#> [3] "/Users/user/Desktop/03033494420148240020.html"

Note that these lawsuits all belong to different TJs. download_cpopg() is able to identify the Justice Court where the lawsuit was filed and automatically look for it in the correct website (for a list of all valid TJs see the Implemented TJs section below).

esaj is able to download lawsuits from many TJs because it is capable of breaking multiple types of captchas (courtesey of the decryptr package). The functions used for this task are not exported, but you can check them out with esaj:::download_noc_lawsuit(), esaj:::download_bw_lawsuit(), and esaj:::download_rgb_lawsuit().

download_cposg() works in the exact same way as download_cpopg(), but, as of the day of this writing, it is only able to download lawsuits filed in São Paulo (TJSP).

ids <- c(
  "1001869-51.2017.8.26.0562",
  "1001214-07.2016.8.26.0565")
download_cposg(ids, "~/Desktop/")
#> [1] "/Users/user/Desktop/10018695120178260562.html"
#> [2] "/Users/user/Desktop/10012140720168260565.html"

The only case where download_cposg() differs in behaviour from download_cpopg() is when the lawsuit turns out to be a list of “closed” lawsuits. If this ever happens, download_cposg() adds some information to the filenames.

download_cposg("00000144420138260352", "~/Desktop/")
#> [1] "/Users/user/Desktop/00000144420138260352_recurso_em_sentido_estrito_2014_09_23.html"
#> [2] "/Users/user/Desktop/00000144420138260352_apelacao_2017_03_24.html"

Implemented TJs

Unfortunately we haven’t yet implemented downloaders for all Justice Courts. These are the ones implemented at the moment:

Court download_cpopg() download_cposg()
Acre (AC) FALSE FALSE
Alagoas (AL) FALSE FALSE
Amapá (AP) FALSE FALSE
Amazonas (AM) TRUE FALSE
Bahia (BA) TRUE FALSE
Ceará (CE) FALSE FALSE
Distrito Federal (DF) FALSE FALSE
Espírito Santo (ES) FALSE FALSE
Goiás (GO) FALSE FALSE
Maranhão (MA) FALSE FALSE
Mato Grosso (MT) FALSE FALSE
Mato Grosso do Sul (MS) FALSE FALSE
Minas Gerais (MG) FALSE FALSE
Pará (PA) FALSE FALSE
Paraíba (PB) FALSE FALSE
Paraná (PR) FALSE FALSE
Pernambuco (PE) FALSE FALSE
Piauí (PI) FALSE FALSE
Rio de Janeiro (RJ) FALSE FALSE
Rio Grande do Norte (RN) FALSE FALSE
Rio Grande do Sul (RS) FALSE FALSE
Rondônia (RO) FALSE FALSE
Roraima (RR) FALSE FALSE
Santa Catarina (SC) TRUE FALSE
São Paulo (SP) TRUE TRUE
Sergipe (SE) FALSE FALSE
Tocantins (TO) FALSE FALSE