I am trying to post a login form to sign into coursera, but I am not yet successful.
With coursera, the login form on the login URL is brought up foreward. Before even posting the login form if I get the website via getURL
, and then writing it to a file, I cannot see the fields related to username and password, basically I do not see the actual form, which by the way using a Firebug or inspect element I can see.
For example if you try the following code, you can see the output html that we get by reading the page.
library(RCurl)
library(XML)
defaultOptions <- curlOptions(
httpheader = list('user-agent'=str_c(R.version$platform,R.version$version.string,sep=", ")),
followlocation = TRUE,
cookiefile = "RCurlCookies.txt",
cainfo = system.file("CurlSSL","cacert.pem", package = "RCurl"))
options(RCurlOptions = defaultOptions)
handle <- getCurlHandle()
url <- getURL("https://www.coursera.org/?authMode=login",
curl = handle, .opts = defaultOptions, ssl.verifyhost = 0L, ssl.verifypeer = 0L)
con <- file("output.html")
writeLines(con = con, url)
close(con)
options(RCurlOptions = list())
So I am guessing that that is why the POST
also does not work, because it does not see the form. If it did then I could use whether RHTMLForms' or use
postForm` to actually authenticate by creating a handle and giving some parameters.
postForm(url, .params = params, curl = curl, style="post", cainfo=signatures)
I wish to be able to post a login form with some username:"username" and some password:"xxxxxxxxxx".
P.S any other method with R would also be good, so far I was able to deal with RSelenium, which has a lot of fuss about browser version, and creating a session, otherwise would have been nice.
I tried using the docker Selenium to interact with the browser and submit forms, and that does not seem to have any problems and works fine. I highly recommend using the Selenium either in R or other languages such as python.