Skip to content

Instantly share code, notes, and snippets.

@jjesusfilho
Last active March 19, 2018 23:57
Show Gist options
  • Save jjesusfilho/d4a1604a383b5263899b641759665e81 to your computer and use it in GitHub Desktop.
Save jjesusfilho/d4a1604a383b5263899b641759665e81 to your computer and use it in GitHub Desktop.
Script para extrair dados da execução penal
library(httr)
library(xml2)
### Função para converter o form em lista
post_form<-function(form){
form<-stringr::str_split(form,"\n")
form<-unlist(form)
nomes<-stringi::stri_extract_first_regex(form,".*(?=:)",omit_no_match=F)
valores<-stringi::stri_extract_first_regex(form,"(?<=:).*",omit_no_match=F)
nomes<-as.list(nomes)
names(nomes)<-nomes
for ( n in 1:length(nomes) ){
nomes[[n]] <- valores[n]
}
return(nomes)
}
## Copiei o form e colei aqui
body<-"ctl00$ScriptManager1:ctl00$CPHPagina$uppCaptcha|ctl00$CPHPagina$btnPesquisar
__LASTFOCUS:
__EVENTTARGET:
__EVENTARGUMENT:
__VIEWSTATE:
__VIEWSTATEENCRYPTED:
__EVENTVALIDATION:
ctl00$CPHPagina$RadioParte:
ctl00$CPHPagina$tbxNome:
ctl00$CPHPagina$NoBot1$NoBot1_NoBotExtender_ClientState:
ctl00$CPHPagina$btnPesquisar:Pesquisar"
body<-post_form(body)
url<-"http://www.tjsp.jus.br/PortalTJ3/Paginas/Pesquisas/VEC/Pesquisa.aspx"
set_config(config(ssl_verifypeer = FALSE))
## Obtêm as informaçes
a<-GET(url)
b<-content(a,"parsed")
## Altera o form/body com as informações obtidas a partir do GET
body$`__VIEWSTATE`<-xml_attrs(xml_find_all(b,"//*[@id='__VIEWSTATE'and @value]"))[[1]][[4]]
body$`__EVENTVALIDATION`<- xml_attrs(xml_find_all(b,"//*[@id='__EVENTVALIDATION' and @value]"))[[1]][[4]]
body$`ctl00$CPHPagina$RadioParte`<-"4"
body$`ctl00$CPHPagina$NoBot1$NoBot1_NoBotExtender_ClientState`<-paste0("-",as.numeric(str_extract(c,"(?<=~)\\d+"))+1)
body$`ctl00$CPHPagina$tbxNome`<-"965009"
c<-POST(url,body=body)
@renancaride
Copy link

Utilizei esta lógica para efetuar uma requisição por um script em php. Mesmo colocando os atributos corretos, inclusive o numero do nobot extender, o retorno é dado como se não tivesse colocado o número correto. Aparentemente hoje há também um controle de tempo para efetuar a requisição no site. Teria alguma ideia para me ajudar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment