使用{RCurl}进行代理服务器验证

bwntbbo3  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(120)

由于不是web-programming方面的Maven,我尝试自动化一项任务,该任务包括进入一个网站,下载一些csv文件,最后将它们导入R中进行数据分析。
在这种情况下,我正在工作下面的示例代码在互联网上找到,这已经定制了一点我的需要,并想知道更多关于产生的错误:

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

谢谢

kx7yvsdv

kx7yvsdv1#

您可以考虑以下对我有效的方法:

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()

相关问题