使用RCurl登录WordPress [英] Login to WordPress using RCurl
问题描述
我想使用R的RCurl软件包登录WordPress网站,以便安装WordPress插件(可能在WordPress的某些选项页面上使用postForm)。由于网站受密码保护,我请求您帮助如何验证我的R会话。
I would like to login into a WordPress website using R's RCurl package in order to install a WordPress plugin (probably use postForm on some options pages in WordPress). Since the website is password protected, I ask for your help in how to authenticate my R session.
我发现以下三个链接相关,但不知道如何使用他们的WordPress:
I found the following three links relevant, but do not know how to use them for WordPress:
- 使用RCurl登录mediawiki
- 使用HttpWebRequest登录Wordpress
- http://r.789695.n4.nabble.com/RCurl-HTTP-Post-td3311942.html
- login to mediawiki using RCurl
- Login Wordpress using HttpWebRequest
- http://r.789695.n4.nabble.com/RCurl-HTTP-Post-td3311942.html
有任何建议吗?
感谢。
推荐答案
使用REDCap处理了类似的东西 - 也可能对你有用。这个简短的例子显示了我如何使用REDCap API来抓取数据。
I've dealt with something similar using REDCap - might be useful for you too. This short example shows how I used the REDCap API to grab data.
library(RCurl)
out <- postForm("https://redcap.url.org/redcap/api/",
token="INSERT TOKEN HERE",
content="record",
type="flat",
format="csv",
.opts=curlOptions(ssl.verifypeer=FALSE))
write(out,file="C:/wherever/out.csv")
请注意,这不适合检查SSL - 我已在以后的版本中改进。我的Google+个人资料中的解释更为冗长: https://plus.google.com/106259574970597769926/posts / U3fVCTV4EdQ
Note that this doesn't do proper checking for SSL - I've improved that in later versions. The more lengthy explanation is on my Google+ profile: https://plus.google.com/106259574970597769926/posts/U3fVCTV4EdQ
看起来你可以使用cURL通过传递正确的参数来登录Wordpress,如下所示:
http://w4dev.com/wp/login-into-wp-using-curl/ a>
It looks like you can use cURL to log into Wordpress by passing the right parameters, as described here: http://w4dev.com/wp/login-into-wp-using-curl/
问题的网址似乎是 http://localhost/wordpress/wp-login.php
并且可以在上面的页面找到重要的参数。基本上,您需要定义用户,他们的密码,以及您想要将它们重定向到网站上的位置。这些是如何在PHP示例中描述的参数
It looks like the URL in question is http://localhost/wordpress/wp-login.php
and the parameters that matter can be found at the page above. Basically, you need to define the user, their password, and where you want to redirect them to on the site afterwards. These are how the parameters are described in that PHP example
"log=". $login_user .
"&pwd=" . $login_pass .
"&wp-submit=Log%20In&redirect_to=" . $visit_url;
基本上,它只是构造一个字符串来发布,看起来像:
Basically, it's just constructing a string to post, which looks something like:
http://yourwordpress.fake/wp-login.php?log=trehman&pwd=abc123456&wp-submit=Log%20In&redirect_to=http://yourwordpress.fake/pageyouwant
因此,您只需更改上面的postForm即可不同的URL和参数,它应该让你认证,然后重定向到你想要的页面。我不是这里的专家,但我确定您可以重定向到另一个带有参数的长网址,这将允许您提交表单或类似的东西。
So, you could just change the postForm above to have a different URL and parameters, and it should get you authenticated and then redirect you to the page you want. I'm not an expert here, but I'm pretty sure that you can redirect to another long URL with parameters, which would let you "submit" a form or something similar.
这篇关于使用RCurl登录WordPress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!