如何获取完整的维基百科修订历史列表?(不想刮)
import wapiti
import pdb
import pylab as plt
client = wapiti.WapitiClient('mahmoudrhashemi@gmail.com')
get_revs = client.get_page_revision_infos( 'Coffee', 1000000)
print len(gen_revs)
500
包链接:
https://github.com/mahmoud/wapiti
发布于 2015-12-31 03:26:44
如果需要500个以上的修订条目,则必须使用
MediaWiki接口
用行动
查询
,属性
修订
和参数
rvcontinue
,它取自前一个请求,因此您不能仅通过一个请求获取整个列表:
https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Coffee&rvcontinue=...
要获得您选择的更具体的信息,您还必须使用
rvprop
参数:
&rvprop=ids|flags|timestamp|user|userid|size|sha1|contentmodel|comment|parsedcomment|content|tags|parsetree|flagged
您可以找到的所有可用参数的摘要
这里
..。
以下是如何在C#中获取完整的维基百科页面修订历史:
private static List GetRevisions(string pageTitle)
{
var url = "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=revisions&rvlimit=500&titles=" + pageTitle;
var revisions = new List();
var next = string.Empty;
while (true)
{
using (var webResponse = (HttpWebResponse)WebRequest.Create(url + next).GetResponse())
{
using (var reader = new StreamReader(webResponse.GetResponseStream()))
{
var xElement = XElement.Parse(reader.ReadToEnd());
revisions.AddRange(xElement.Descendants("rev"));
var cont = xElement.Element("continue");
if (cont == null) break;
next = "&rvcontinue=" + cont.Attribute("rvcontinue").Value;
}
}
}
return revisions;
}
当前用于
“咖啡”
这将返回
10414
修订。
编辑:
这是一个Python版本:
import urllib2
import re
def GetRevisions(pageTitle):
url = "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=revisions&rvlimit=500&titles=" + pageTitle
revisions = [] #list of all accumulated revisions
next = '' #information for the next request
while True:
response = urllib2.urlopen(url + next).read() #web request
revisions += re.findall(']*>', response) #adds all revisions from the current request to the list
cont = re.search('
revisions = GetRevisions("Coffee")
print(len(revisions))
#10418
for i in revisions[0:10]:
print(i)
#
#
#
#
#
#
#
#
#
#
发布于 2017-07-08 03:28:49
如果你使用pywikibot,你可以拉出一个生成器,它将为你运行完整的修订历史。例如,要获得一个生成器,该生成器将遍历英文维基百科中的页面"pagename“的所有修订(包括其内容),请使用:
site = pywikibot.Site("en", "wikipedia")
page = pywikibot.Page(site, "pagename")
revs = page.revisions(content=True)
您可以将更多的参数应用于查询。您可以找到API文档
这里
值得注意的是:
版本(reverse=False、total=None、content=False、rollback=False、starttime=None、endtime=None)
作为修订实例加载版本历史的生成器。
pywikibot似乎是许多维基百科编辑人员自动化编辑的方法。
https://stackoverflow.com/questions/34411896
复制相似问题