使用RCurl登录mediawiki [英] login to mediawiki using RCurl
问题描述
如何使用RCurl登录到mediawiki(或者Curl,我可以将其修改为R包)
how can I login to a mediawiki with RCurl (or Curl, and I can adapt it to the R package)?
我只想解析一个页面,我需要登录,否则我无法访问它。
I just want to parse a page but I need to login otherwise I can't access it.
推荐答案
Mediawiki API有一个登录函数, 。您必须保存并发送回API才能验证会话和登录。下面是一个在bash中使用curl和XMLstarlet的方法:
The Mediawiki API has a login function which returns cookies and a token. You have to save and send both back to the API in order to authenticate the session and login. Here's a way to do it with curl and XMLstarlet in bash:
发送一个登录令牌的请求,保存cookies.txt和output.xml中的输出
Send a request for a login token, saving the cookies in cookies.txt and the output in output.xml.
curl -c cookies.txt -dlgname = YOURNAME& lgpassword = YOURPASS& action = login& format = xmlhttp: /your.mediawikiinstall.com/w/api.php -o output.xml
然后使用XMLstarlet将令牌拉出xml,并将其另存为bash变量。
Then pull the token out of the xml using XMLstarlet, and save that as a bash variable.
YOURTOKEN = $(xml sel -t -m'// login'-v'// @ token'output.xml)
然后发送登录请求,包括cookie文件和令牌。
Then send the login request, including the cookie file and the token.
curl -b cookies.txt -daction = login& lgname = YOURNAME& lgpassword = YOURPASS& format = xml& lgtoken =$ YOURTOKEN http://your.mediawikiinstall .com / w / api.php
这篇关于使用RCurl登录mediawiki的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!