Logging into site with R, what error?

Asked

Viewed 54 times

2

I’m trying to log into a site, the value site is merely illustrative, someone knows why the function is not working?

  login <- function (xxxx_user, xxxx_pass) {

      url_login <- 'http://www.valor.com.br/login'

      curlhand <- getCurlHandle()

      curlSetOpt(
        .opts = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")),
        cookiefile = "cookies.txt",
        useragent = 'YOUR R-PACKAGE NAME',
        followlocation = TRUE,
        # might need this in case the server checks for the referer..
        httpheader = "Referer: http://www.valor.com.br",
        curl = curlhand)

      # (1) first call to initializate session. you get the session cookie
      getURL(url_login, curl = curlhand)

      params<- list( login = xxxx_user, password = xxxx_pass )
      # might need to add some other hidden form param in case there are..

      # (2) second call, sends the form, along with a session cookie
      html = postForm(url_login, 
                      .params = params, 
                      curl = curlhand, 
                      style="POST")

      # ... perform some grep logic with 'html' to find out weather you are connected 
    }

    # you call the function...
    login("seulogin", "suasenha")

This appears in R: Failed to connect to www.valor.com.br port 80: Timed out

Vlw!!!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.