2

I would like to know if pywikibot api allows to retrieve the redirects of a given wikipedia article.

I tried the following.

pw.Page(pw.Site('en'), 'forensics').showRedirects()
pw.Page(pw.Site('en'), 'forensics').redirects()

However, I got an error saying AttributeError: 'Page' object has no attribute 'showRedirects'

I am happy to provide more details if needed.

EmJ
  • 4,398
  • 9
  • 44
  • 105

1 Answers1

2

Use backlinks:

page.backlinks(filter_redirects=True)

Side note: There is also getReferences:

page.getReferences(filter_redirects=True)

but this is not the same as backlinks. page.getReferences(filter_redirects=True) returns pages that are

  • redirects (but not necessary a redirect to the page)
  • contain a reference to the page

This is rare, but happens. For example assuming that page A contains the following wikitext:

#Redirect[[C]]
{{B}}

This page will be returned by Page(site, 'B').getReferences(filter_redirects=True), but not by Page(site, 'B').backlinks(filter_redirects=True).

AXO
  • 8,198
  • 6
  • 62
  • 63