2

我正在使用以下代码来获取给定维基百科页面的讨论页面。

import pywikibot as pw
page = pw.Page(pw.Site('en'), 'Elon_Musk')
talkpage = page.toggleTalkPage()
talkpage.text

这工作正常,但它不会返回所有存档的讨论页。有没有一种方法可以以编程方式查找给定讨论页的档案并遍历它们以获取文本?

非常感谢!

4

1 回答 1

1

You can get all subpages with the following code:

import pywikibot as pw
site = pw.Site('en', 'wikipedia')
for page in site.allpages(prefix='Elon Musk/', namespace='Talk'):
    print(page.title())
    print(page.text)

There exists a page "Talk:Elon_Musk/FAQ". If you don't want to include this page and similar ones, you need to add an additional line before returning the text: if 'Archive' in page.title(): .

于 2020-02-27T17:30:03.970 回答