使用 pywikibot 的维基百科修订历史 [英] Wikipedia revision history using pywikibot

查看:66
本文介绍了使用 pywikibot 的维基百科修订历史的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一次性收集所有修订历史数据.Pywikibot page.revisions() 没有获取更改的字节数的参数.它为我提供了所需的所有数据,但更改的字节数除外.

I want to collect all the revisions history data at once. Pywikibot page.revisions() does not have the parameter to fetch number of bytes changed. It gives me all the data that I need except the number of bytes changed.

如何更改字节数?

例如:对于文章主页,修订历史是这里:历史截图

for example: for the article Main Page the revision history is here: history screenshot

我当前的代码:

import pywikibot

site = pywikibot.Site("en", "wikipedia")
page = pywikibot.Page(site, "Main_Page")
revs = page.revisions()

仅显示 1 个输出:

first entry:  {'revid': 969106986, '_text': None, 'timestamp': Timestamp(2020, 7, 23, 12, 44, 21), 'user': 'The Blade of the Northern Lights', 'anon': False, 'comment': 'OK, there we go.', 'minor': False, 'rollbacktoken': None, '_parent_id': 969106918, '_content_model': None, '_sha1': 'eb9e0167aabe4145be44305b3775837a37683119', 'slots': {'main': {'contentmodel': 'wikitext'}}}

我需要更改的字节数,在修订历史链接中显示为 {+1, -1, +1, -2},也可以在上面的历史截图中看到.

I need the number of bytes changed which is shown as {+1, -1, +1, -2} in the revision history link which can also be seen in the history screenshot above.

推荐答案

AXO 的提议有更好的方法:

There is a better way to AXO's proposal:

import pywikibot
site = pywikibot.Site('wikipedia:en')
page = pywikibot.Page(site, 'Main Page')
for rev in page.revisions(total=5):
    # do whatever you want with Revision Collection rev
    print(dict(timestamp=str(rev.timestamp), size=rev.size))

代码将按预期打印:

{'timestamp': '2021-02-03T11:11:30Z', 'size': 3508}
{'timestamp': '2021-02-03T11:03:39Z', 'size': 3480}
{'timestamp': '2020-11-10T08:18:07Z', 'size': 3508}
{'timestamp': '2020-11-10T02:32:23Z', 'size': 4890}
{'timestamp': '2020-11-10T00:46:58Z', 'size': 4880}

这篇关于使用 pywikibot 的维基百科修订历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆