# -*- coding: utf-8 -*-
import io,sys,ssl,urllib.request,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
def get(u):
    req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
    h=urllib.request.urlopen(req,timeout=25,context=ctx).read().decode("utf-8","ignore")
    t=re.sub(r"<script.*?</script>","",h,flags=re.S); t=re.sub(r"<style.*?</style>","",t,flags=re.S)
    t=re.sub(r"<[^>]+>"," ",t); t=re.sub(r"\s+"," ",t).strip()
    return h,t
urls=[
 "https://cse.nd.edu/graduate/",
 "https://cse.nd.edu/graduate/handbook",
 "https://graduateschool.nd.edu/admissions/",
 "https://graduateschool.nd.edu/admissions/international-applicants/",
]
for u in urls:
    try:
        h,t=get(u); print("\n####",u,"LEN",len(h),"TEXT",len(t))
        for kw in ["TOEFL","IELTS","Duolingo","tuition","GPA","deadline","credit","STEM","OPT","minimum","score"]:
            i=t.lower().find(kw.lower())
            if i>=0: print("["+kw+"]",t[max(0,i-50):i+150])
    except Exception as e:
        print("ERR",u,type(e).__name__,e)
