User:Ifeanyi liam/Outreachy 3
Jump to navigation
Jump to search
def parse_page(prop, term, page): import pywikibot as pw import re # task_3: to load a wikipedia page. # The Igbo-Ukwu page from the english article. site = pw.Site('en', 'wikipedia') # getting the page... wk_page = pw.Page(site, page) # loading the page... text = wk_page.get() # just getting one search item using search. # rather than getting a list. value = re.findall(term, text) print(f"{prop}: {value}") parse_page("P18", "^|Image= \[*(\S.+)\|", 'Grimsby') parse_page("P94", "^|Arms= \[*(\S.+)\|", 'Grimsby') parse_page("P1398", "^|Replace= \[*(\S.+)\]*", 'Grimsby') parse_page("P1082", "^|population_total\s*= (.+)", 'Igbo-Ukwu') parse_page("P172", "^|population_blank1\s*= \[*(.*)\|", 'Igbo-Ukwu') parse_page("P2907", "^| utc_offset\s*= (.+)", 'London') parse_page("P1082", "^| population_total\s*= ([0-9,]*)", 'London') parse_page("P2044", "^| elevation_m\s*= ([0-9]*)", 'London') parse_page("P281", "^| postal_code\s*= (.+)", 'Prague') parse_page("P1259", "^| coordinates\s*= \{\{(.+)\}*", 'Prague') parse_page("P1449", "^| nickname\s*= \'\'(.+)\'\'", 'Prague')