# -*- coding: utf-8 -*-
__author__ = 'eso'
import sys
sys.path.append('../../')
import re
from pywikibot import Page, Site
from pywikibot.pagegenerators import LinksearchPageGenerator, SearchPageGenerator

wiki = Site()

searcher = SearchPageGenerator('insource:http://www.ub.uni-bielefeld.de/diglib', site=wiki)

print(type(searcher))

for idx, page in enumerate(searcher):
    print(idx, page)
    temp_text = page.text
    if re.search('\[http:\/\/www.ub.uni\-bielefeld.de', temp_text):
        temp_text = re.sub('\[http:\/\/www.ub.uni\-bielefeld.de\/diglib\/aufkl\/journalfranken\/journalfranken.htm UB Bielefeld\]', '{{Bielefeld|2096404}}', temp_text)
        temp_text = re.sub('\[http:\/\/www.ub.uni\-bielefeld.de\/diglib\/2006\/fontane_gedichte\/ UB Bielefeld\]', '{{Bielefeld|1682441}}', temp_text)
        temp_text = re.sub('\[http:\/\/www.ub.uni\-bielefeld.de\/diglib\/2005\/muehsam_erde\/ Digitale Drucke der Uni Bielefeld\]',
                           '{{Bielefeld|1660345}}', temp_text)
        temp_text = re.sub('\[http:\/\/www.ub.uni\-bielefeld.de\/diglib\/aufkl/browse\/neuethalia\/11792.html Uni Bielefeld\]',
                           '{{Bielefeld|2300223_001}}', temp_text)
        temp_text = re.sub('\[http:\/\/www.ub.uni\-bielefeld.de\/diglib\/aufkl\/browse\/neuethalia\/21792.html Uni Bielefeld\]',
                           '{{Bielefeld|2300223_002}}', temp_text)
        temp_text = re.sub('\[http:\/\/www.ub.uni\-bielefeld.de\/diglib\/aufkl\/browse\/neuethalia\/11793.html Uni Bielefeld\]',
                           '{{Bielefeld|2300223_003}}', temp_text)
        temp_text = re.sub('\[http:\/\/www.ub.uni\-bielefeld.de\/diglib\/aufkl\/browse\/neuethalia\/21793.html Uni Bielefeld\]',
                           '{{Bielefeld|2300223_004}}', temp_text)
        temp_text = re.sub('\[http:\/\/www.ub.uni\-bielefeld.de\/diglib\/aufkl\/thalia\/thalia.htm UB Bielefeld\]',
                           '{{Bielefeld|1944380}}', temp_text)
    if page.text != temp_text:
        page.text = temp_text
        try:
            page.save(botflag=True, summary='http://www.ub.uni-bielefeld.de/ -> Bielefeld')
        except Exception as exception:
            print(exception)
            continue



@@ -492,32 +492,37 @@
        temp_text
+, bla
  = re.sub('%5C%5Bhtt
@@ -506,32 +506,33 @@
 xt, bla = re.sub
+n
 ('%5C%5Bhttp:%5C/%5C/www
@@ -666,32 +666,37 @@
        temp_text
+, bla
  = re.sub('%5C%5Bhtt
@@ -680,32 +680,33 @@
 xt, bla = re.sub
+n
 ('%5C%5Bhttp:%5C/%5C/www
@@ -823,32 +823,37 @@
        temp_text
+, bla
  = re.sub('%5C%5Bhtt
@@ -837,32 +837,33 @@
 xt, bla = re.sub
+n
 ('%5C%5Bhttp:%5C/%5C/www
@@ -1024,32 +1024,37 @@
        temp_text
+, bla
  = re.sub('%5C%5Bhtt
@@ -1038,32 +1038,33 @@
 xt, bla = re.sub
+n
 ('%5C%5Bhttp:%5C/%5C/www
@@ -1225,32 +1225,37 @@
        temp_text
+, bla
  = re.sub('%5C%5Bhtt
@@ -1239,32 +1239,33 @@
 xt, bla = re.sub
+n
 ('%5C%5Bhttp:%5C/%5C/www
@@ -1427,32 +1427,37 @@
        temp_text
+, bla
  = re.sub('%5C%5Bhtt
@@ -1441,32 +1441,33 @@
 xt, bla = re.sub
+n
 ('%5C%5Bhttp:%5C/%5C/www
@@ -1629,32 +1629,37 @@
        temp_text
+, bla
  = re.sub('%5C%5Bhtt
@@ -1643,32 +1643,33 @@
 xt, bla = re.sub
+n
 ('%5C%5Bhttp:%5C/%5C/www
@@ -1839,16 +1839,21 @@
 emp_text
+, bla
  = re.su
@@ -1853,16 +1853,17 @@
 = re.sub
+n
 ('%5C%5Bhttp

make all changes together