Reputation: 687
Being not an expert on web-programming
, I attempt to automate a task which consists of getting into a website, download some csv
files, and finally import them in R for data analysis.
In this context, I am working on the below sample code found on internet, which has been customized a bit to my need, and wonder to know more about the resulting error:
library(RCurl)
curl = getCurlHandle()
curlSetOpt(cookiejar = 'cookies.txt', followlocation = TRUE, autoreferer =
TRUE, curl = curl)
# Load the page for the first time to capture VIEWSTATE:
html <- getURL('https://www.olisnet.com/OlisAuthenticate/JSP/login.jsp',
curl = curl,
.opts=list(ssl.verifypeer=FALSE))
# Extract VIEWSTATE with a regular expression or any other tool:
viewstate <- as.character(sub('.*id="__VIEWSTATE" value="([0-9a-zA-
Z+/=]*).*', '\\1', html))
# Set the parameters as your username, password and the VIEWSTATE:
params <- list(
'user' = '<USERNAME>',
'pass' = '<PASSWORD>',
'__VIEWSTATE' = viewstate
)
html = postForm('https://www.olisnet.com/OlisAuthenticate/JSP/login.jsp',
.params = params, curl = curl,.opts=list(ssl.verifypeer=FALSE))
Error: Proxy Authentication Required
# Verify if you are logged in:
grepl('Logout', html)
[1]FALSE
Thanks
Upvotes: 1
Views: 342
Reputation: 2213
You can consider the following approach which worked for me :
library(RSelenium)
rd <- rsDriver(chromever = "105.0.5195.52", browser = "chrome", port = 4480L)
remDr <- rd$client
remDr$open()
url <- "https://www.olisnet.com/OlisAuthenticate/JSP/login.jsp"
remDr$navigate(url)
web_Obj_Id <- remDr$findElement("id", "PIN")
web_Obj_Id$sendKeysToElement(list("myusername"))
web_Obj_First_GoButton <- remDr$findElement("id", "boutonGo")
web_Obj_First_GoButton$clickElement()
web_Obj_Password <- remDr$findElement("id", "PWD")
web_Obj_Password $sendKeysToElement(list("mypassword"))
web_Obj_Second_GoButton <- remDr$findElement("css selector", "#form-step-2 > div > div > button")
web_Obj_Second_GoButton$clickElement()
Upvotes: 0