# -*- coding: utf-8 -*-
import urllib.request, ssl, re, io, sys
sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding="utf-8")
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
url="https://uwaterloo.ca/future-graduate-students/programs/by-faculty/math/pure-mathematics-master-mathematics-mmath"
html=urllib.request.urlopen(urllib.request.Request(url,headers={"User-Agent":"Mozilla/5.0"}),timeout=25,context=ctx).read().decode("utf-8","ignore")
txt=re.sub(r"<script[\s\S]*?</script>"," ",html); txt=re.sub(r"<style[\s\S]*?</style>"," ",txt); txt=re.sub(r"<[^>]+>"," ",txt)
for a,b in [("&nbsp;"," "),("&amp;","&"),("&#039;","'"),("&quot;",'"')]: txt=txt.replace(a,b)
txt=re.sub(r"\s+"," ",txt)
i=txt.find("Application materials"); j=txt.find("Tuition",i)
print(txt[i:j].strip())
print("\nGRE x",txt.count("GRE")," GMAT x",txt.count("GMAT"))
for kw in ["Resume","resume","CV","statement","Statement","motivation","cover letter"]:
    print(kw, txt.count(kw))
