Last active
May 1, 2017 04:53
-
-
Save jjesusfilho/5de8ab740bada5ef3d6c0af134da164f to your computer and use it in GitHub Desktop.
Função para baixar o inteiro teor dos acordos e convenções coletivos do sistema mediador do Ministério do Trabalho
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(RCurl) | |
| library(XML) | |
| library(stringi) | |
| mediador_inteiro_teor<-function(solicitacao,download=TRUE,vector=TRUE){ | |
| url<-paste0("http://www3.mte.gov.br/sistemas/mediador/Resumo/ResumoVisualizar?NrSolicitacao=",solicitacao) | |
| ## Cria um objeto a parte para usá-lo a fim de nomear os arquivos a serem baixados | |
| s<-as.character(solicitacao) | |
| s<-stri_replace_first_regex(s,"/","_") | |
| ## Inicia o loop para baixar os textos. | |
| inteiro.teor<-"" | |
| for(i in 1:length(s)){ | |
| s1<-getURL(url[i]) | |
| s1<-htmlParse(s1,encoding="UTF-8") | |
| s1<-xpathApply(s1,"//*[@class='titulo' or @align='justify' or @class='textosubgrupo'or @class='tituloClausula' or @class='textonome' or @class='descricaoClausula']",xmlValue) | |
| s1<-toString(unlist(s1)) | |
| s1<-stri_replace_all_regex(s1,"\\s+,","\n") | |
| if(vector==TRUE) inteiro.teor[i]<-s1 | |
| if(download==TRUE) write(s1,paste0(s[i],".txt")) | |
| } | |
| return(inteiro.teor) | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment