Bindini
Bindini

Reputation: 189

Filling form to get meteorological data on a website using RCurl in R

I´m trying to get rainfall data from INMET website. First it needs to post a form with username and password, and then, fill a form with some parameters.

I´m trying first to set the login parameters with "postform" function from package Rcurl, and then generate the url to access data.

params<-list('E-mail do Usuário' = "username", 'Senha' = "xxxxx") #grabbed from html text
html<-postForm('http://www.inmet.gov.br/projetos/rede/pesquisa/inicio.php', params = params, curl = getCurlHandle(), style="POST")
station<-"83630"
startdate<-"01/01/1981"
enddate<-"01/01/2018"
url.data<-sprintf("http://www.inmet.gov.br/projetos/rede/pesquisa/gera_serie_txt.php?&mRelEstacao=%s&btnProcesso=serie&mRelDtInicio=%s&mRelDtFim=%s&mAtributos=,,,,,,,,,,1,,,,,,", station, startdate, enddate)

url.data is the final URL which I can access the data via html

I´m a bit stuck on this, but I guess I'm almost there.

Upvotes: 0

Views: 48

Answers (1)

hrbrmstr
hrbrmstr

Reputation: 78832

I can't get beyond the login since I don't have an account. For the login, that site makes a POST request that ultimately looks like this:

POST /projetos/rede/pesquisa/inicio.php HTTP/1.1
Host: www.inmet.gov.br
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:64.0) Gecko/20100101 Firefox/64.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.7,fr-BE;q=0.3
Referer: http://www.inmet.gov.br/projetos/rede/pesquisa/inicio.php
Content-Type: application/x-www-form-urlencoded
Content-Length: 78
Connection: close
Cookie: PHPSESSID=0j7eg8u12gka0c774aalahm9s0
Upgrade-Insecure-Requests: 1

mUsuario=USERNAME&mGerModulo=PES&mCod=a&mSenha=PASSWORD&mGerModulo=PES&btnProcesso=+Acessar+

So, it's passing in a few other query parameters. As a list they look like this:

list(
  mUsuario = "USERNAME", 
  mGerModulo = "PES", 
  mCod = "a", 
  mSenha = "PASSWORD", 
  mGerModulo = "PES", 
  btnProcesso = "+Acessar+"
)

NOTE that you need to use the input form name vs the text of the form. I have no idea if you need to keep passing the user/pass for every request not can I help with any other requests since I cannot go past the login page.

Upvotes: 1

Related Questions