Reputation: 238
I am using the following code to fetch talk page for a given Wikipedia page.
import pywikibot as pw
page = pw.Page(pw.Site('en'), 'Elon_Musk')
talkpage = page.toggleTalkPage()
talkpage.text
This works fine, but it does not return all archived talk pages. Is there a way I can programmatically find archives for a given talk page and loop through them to get the text?
Many thanks!
Upvotes: 2
Views: 203
Reputation: 2826
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():
.
Upvotes: 1