# -*- 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
u="https://www.sgs.utoronto.ca/programs/computer-science/"
try:
    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")
    print("len=",len(raw))
    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"\s+"," ",tt)
    print(tt[:2200])
    for kw in ["degree","coursework","research","thesis","credit","full-time","deadline","TOEFL","IELTS","GRE","tuition","length","months","STEM","co-op","master"]:
        k=tt.lower().find(kw.lower())
        if k>=0: print(f"\n[{kw}] ...{tt[max(0,k-80):k+220]}...")
except Exception as e:
    print("ERR",type(e).__name__,str(e)[:120])
