使用{RCurl}进行代理身份验证

时间:2016-02-18 11:37:39

标签: r curl web

我不是web-programming的专家,我尝试自动完成一项任务,包括进入网站,下载一些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

由于

0 个答案:

没有答案