使用RCurl登录php网站
我想用R访问php网站的内容使用RCurl登录php网站,php,r,login,rcurl,Php,R,Login,Rcurl,我想用R访问php网站的内容 我在url中传递了一个登录+密码的示例,但我不知道如何通过url按下登录按钮 如果可能的话,我想使用R包RCurl。表单通过post提交-您目前正在使用get请求。从外观上看,您需要使用post 我猜rcurl是基于curl的-我知道curl可以做到这一点,所以应该是可能的。表单通过post提交-从外观上看,您目前正在使用get请求,您需要使用post 我猜rcurl是基于curl的——我知道curl可以做到这一点,所以应该是可能的。最近我也遇到了同样的问题。在我
我在url中传递了一个登录+密码的示例,但我不知道如何通过url按下登录按钮
如果可能的话,我想使用R包RCurl。表单通过post提交-您目前正在使用get请求。从外观上看,您需要使用post
我猜rcurl是基于curl的-我知道curl可以做到这一点,所以应该是可能的。表单通过post提交-从外观上看,您目前正在使用get请求,您需要使用post
我猜rcurl是基于curl的——我知道curl可以做到这一点,所以应该是可能的。最近我也遇到了同样的问题。在我的例子中,我使用RCurl包(带有POST请求)解决了这个问题 在这段代码中,两个请求一个接一个地完成。第一个是为了获得会话cookie(在服务器中启动会话)。我调用的应用程序希望会话在检查登录凭据时启动(如果预先发送表单,则不会发生这种情况)。否则,会发出一些关于不支持cookie的警告。这可能是询问者的情况(尽管那是很久以前的事了)。。。或者其他人的
login <- function (xxxx_user, xxxx_pass) {
url_login <- 'http://centralgreen.com.sg/login.php'
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://centralgreen.com.sg",
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("yourusername", "yourpass")
login最近我也遇到了同样的问题。在我的例子中,我使用RCurl包(带有POST请求)解决了这个问题
在这段代码中,两个请求一个接一个地完成。第一个是为了获得会话cookie(在服务器中启动会话)。我调用的应用程序希望会话在检查登录凭据时启动(如果预先发送表单,则不会发生这种情况)。否则,会发出一些关于不支持cookie的警告。这可能是询问者的情况(尽管那是很久以前的事了)。。。或者其他人的
login <- function (xxxx_user, xxxx_pass) {
url_login <- 'http://centralgreen.com.sg/login.php'
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://centralgreen.com.sg",
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("yourusername", "yourpass")
登录我怀疑这个网站会接受GET的密码。如果他们这样做是不安全的,我建议使用post-have-updated-answer来清除我尝试了r=postForm(“,.params=list(login=“9-1501”,password=“mypassword”)),但没有成功(它返回原始php页面的源代码)稍微分析一下标题。邮报也在发送其他参数。登录:9-1501 |密码:acb | Button | u DoLogin.x:38 | Button | u DoLogin.y:8 | Button | u DoLogin:login。也许他们是必需的。我怀疑这个网站会接受密码与获取。如果他们这样做是不安全的,我建议使用post-have-updated-answer来清除我尝试了r=postForm(“,.params=list(login=“9-1501”,password=“mypassword”)),但没有成功(它返回原始php页面的源代码)稍微分析一下标题。邮报也在发送其他参数。登录:9-1501 |密码:acb | Button | u DoLogin.x:38 | Button | u DoLogin.y:8 | Button | u DoLogin:login。也许它们是必需的。我正在尝试那里提供的例子我正在尝试那里提供的例子