Run this code:
import pywikibot import re from pywikibot import pagegenerators from pywikibot import textlib site = pywikibot.Site() pattern = textlib.FILE_LINK_REGEX % '|'.join(site.namespaces[6]) regex = re.compile(pattern, re.VERBOSE) pywikibot.output(regex.pattern) def my_replace(match): pywikibot.output(match) for page in pagegenerators.RandomPageGenerator(total=100, site=site, namespaces=[0]): page.get() pywikibot.output(page.title()) regex.sub(my_replace, page.text)
When you bump into an article with a file having a wikilink inside its caption (like [[File:ABC.jpg|123px|text [[Lorem ipsum]] text]]), the bot stops printing and just gets stuck.