# -*- coding: utf-8 -*-
import io,sys,urllib.request,ssl,re
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
base="https://web.cs.toronto.edu"
pages={"/graduate/how-to-apply":["TOEFL","IELTS","Duolingo","English","language","GRE","recommendation","transcript","statement","CV","deadline","December","document","application fee"],
"/graduate/funding-tuition-awards":["tuition","fee","$","funding","award","scholarship","stipend","domestic","international"],
"/graduate/faq":["TOEFL","IELTS","English","language","GRE","supervisor","B+","average","course","credit","thesis","project"]}
for p,kws in pages.items():
    u=base+p
    req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
    raw=urllib.request.urlopen(req,context=ctx,timeout=25).read().decode("utf-8","ignore")
    tt=re.sub(r"<script[\s\S]*?</script>","",raw)
    tt=re.sub(r"<style[\s\S]*?</style>","",tt)
    tt=re.sub(r"<[^>]+>"," ",tt)
    tt=re.sub(r"&nbsp;"," ",tt); tt=re.sub(r"&amp;","&",tt); tt=re.sub(r"&#8217;","'",tt); tt=re.sub(r"&mdash;","-",tt); tt=re.sub(r"\s+"," ",tt)
    print("\n##########",p)
    seen=set()
    for kw in kws:
        for m in re.finditer(re.escape(kw),tt,re.I):
            k=m.start(); seg=tt[max(0,k-90):k+220]
            key=seg[:40]
            if key in seen: continue
            seen.add(key)
            print(f"[{kw}] ...{seg}...")
            break
