User:ST47/search

import pywikibot import re

page_name = u"page to search in" target_regex = r"some regex to search for"

site = pywikibot.Site page = pywikibot.Page(site, page_name)

active_flag = False active_track = None revdel_string = ''

for rev in page.revisions: text = page.getOldVersion(rev.revid) if text: if re.search(target_regex, text): print(f"Match in revision {rev.revid}") if not active_flag: active_flag = True active_track = rev.revid else: print(f"No match in revision {rev.revid}") if active_flag: active_flag = False new_string = f"{last_revid}..{active_track}" if revdel_string: revdel_string = new_string + '|' + revdel_string else: revdel_string = new_string last_revid = rev.revid print(f"https://en.wikipedia.org/w/index.php?title={page_name}&action=history&limit=5000&revdel_select={revdel_string}")