# -*- 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 (Windows NT 10.0; Win64; x64)"})
    with urllib.request.urlopen(req,timeout=25,context=ctx) as r:
        return r.status,r.read().decode("utf-8","replace")
def clean(h):
    t=re.sub(r"<script[\s\S]*?</script>","",h)
    t=re.sub(r"<style[\s\S]*?</style>","",t)
    t=re.sub(r"<[^>]+>"," ",t); return re.sub(r"\s+"," ",t)
for u in ["https://grad.uchicago.edu/admissions/apply/english-language-requirements/required-scores/",
          "https://grad.uchicago.edu/admissions/apply/english-language-requirements/"]:
    try:
        st,h=get(u); t=clean(h)
        print("====",u,st,"len",len(t))
        for kw in ["TOEFL","IELTS","score","90","100","7.0","6.5","Duolingo","minimum","overall","speaking","listening"]:
            for m in re.finditer(re.escape(kw),t):
                a=max(0,m.start()-100); b=min(len(t),m.end()+180)
                print(" -",kw,"…",t[a:b].strip()[:300]); break
    except Exception as e:
        print("====",u,"ERR",repr(e))
