R – CVM data download via POST method (package httr)

Question:

I'm trying to build a function in R to download multiple documents directly from the system provided by CVM.

General instructions given by CVM for multiple downloads are described at: http://sistemas.cvm.gov.br/Port/DownloadArqs/download02.htm

In summary, access to the system depends on authentication via login and password and requires that the query parameters be informed via the POST method. The system will respond in XML, providing the URLs for downloading the documents.

What I want to do is return in R the list containing these URLs. For that, I tried to write a simple function using the "httr" package, described below:

sist_cvm <- "https://www.rad.cvm.gov.br/DOWNLOAD/SolicitaDownload.asp"

login <- list(txtLogin = "MEU_LOGIN", txtSenha = "MINHA_SENHA", txtData = "15/04/2015", txtHora = "00:00", txtDocumento = "4")

library(httr)

acesso <- POST(url=sist_cvm, body=login, encode="multipart", verbose())

However, when trying to run, it returns the following error:

SSL certificate problem: Error in function (type, msg, asError = TRUE)

Note: I tried to do multiple combinations when writing the POST function, varying encode like form , multipart and json , as well as including or omitting verbose() . I also tried to replace the login and password of the elements list login to authenticate("MEU_LOGIN", "MINHA_SENHA") . In all cases, the same error was returned.

Could anyone give me any suggestions please?

Thanks!

Answer:

It seems that in the latest version of the httr package this problem is solved. Below is a code that worked:

cvm <- "https://WWW.RAD.CVM.GOV.BR/DOWNLOAD/SolicitaDownload.asp"

informs <- list(txtLogin = "seulogin", 
          txtSenha = "suasenha", 
          txtData = format(Sys.Date(), "%d/%m/%Y"), 
          txtHora = "00:00", 
          txtDocumento = "TODOS")

acesso <- POST(url = cvm, 
           body = informs, 
           encode = "form", 
           verbose())

To.

Scroll to Top