用户:Air7538-bot/task/4

import pywikibot
import time
import re
site = pywikibot.Site('zh','wikipedia')
title = "User:Air7538/沙盒03"
page = pywikibot.Page(site,title)
titleTest = re.findall("\[\[(.*?)\]\]",page.text,re.IGNORECASE)
for i in range(len(titleTest)):
    if "Special:链入页面" in titleTest[i]:
        continue
    page = pywikibot.Page(site,titleTest[i])
    TemplateBreadcrumb2 = re.findall("{{Breadcrumb2.*?}}",page.text,re.DOTALL)
    for i in range(len(TemplateBreadcrumb2)):
        print(TemplateBreadcrumb2)
        if page.namespace().id == 0:
            page.text = page.text.replace(TemplateBreadcrumb2[i],"")
            edit_summary = "移除不应该出现在条目空间的模板参见[[Template:Breadcrumb2]],"
            page.save(edit_summary)
        time.sleep(1)

2022-02-17清理三个链入。