我怎样才能得到完整的维基百科修订历史列表?(不想刮)
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
Tags:
如果您需要500多个修订条目,则必须使用MediaWiki API和action查询、属性修订和参数rvcontinue,这是从上一个请求中获取的,因此您不能仅通过一个请求获得整个列表:
要获得您选择的更具体的信息,还必须使用rvprop参数:
^{pr2}$可以找到here的所有可用参数的摘要。在
以下是如何在C中获取完整的Wikipedia页面修订历史记录:
目前对于“Coffee”,此返回值10414修订。在
编辑:以下是Python版本:
你对逻辑的看法完全相同。与C的不同之处在于,在C中,我解析了XML响应,这里我使用regex来匹配其中的所有}元素。在
rev
和{所以,我的想法是做一个main request,从中我得到所有修订(最大值是500)到
revisions
数组中。我还检查了continue
xml元素,以了解是否还有更多的修订,获取rvcontinue
属性的值,并在next
变量中使用它(对于本例中的第一个请求,它是20150127211200|644458070
),使another request接受下一个500个修订。我重复这一切,直到continue
元素可用为止。如果它丢失了,这意味着在响应的修订列表中的最后一个修订之后不再有修订,所以我退出循环。在下面是“Coffee”文章的最后10个修订(它们是从API中以相反的顺序返回的),不要忘了,如果需要更具体的修订信息,可以在请求中使用
rvprop
参数。在如果您使用pywikibot,您可以拉一个生成器,它将为您运行完整的修订历史记录。例如,要获得一个生成器,该生成器将逐步检查英文Wikipedia中页面“pagename”的所有修订(包括其内容),请使用:
还有很多参数可以应用于查询。您可以找到API文档here
值得注意的是:
pywikibot似乎是许多wikipedia编辑自动化编辑的方法。在
相关问题 更多 >
编程相关推荐