# -*- 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/applied-mathematics-master-math-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)
for kw in ["five","areas","fluid","differential","optimization","biomathematics","quantum","scientific","computational","dynamics","gaps","fourth year"]:
    i=txt.lower().find(kw.lower())
    if i>=0: print(kw,"…",txt[max(0,i-100):i+200].strip(),"\n")
for kw in ["GRE","GMAT"]:
    print(kw,"出现",txt.count(kw),"次")
