# -*- 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
u="https://grad.uchicago.edu/admissions/apply/english-language-requirements/"
req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
h=urllib.request.urlopen(req,timeout=25,context=ctx).read().decode("utf-8","replace")
t=re.sub(r"<script[\s\S]*?</script>","",h); t=re.sub(r"<style[\s\S]*?</style>","",t)
t=re.sub(r"<[^>]+>"," ",t); t=re.sub(r"\s+"," ",t)
for kw in ["Pritzker","Molecular Engineering","PME","100","90","7.0","6.5","minimum score","vary"]:
    i=t.lower().find(kw.lower())
    if i>=0: print(kw,"::",t[max(0,i-80):i+160])
print("---- score table snippets ----")
for m in re.finditer(r"(TOEFL[^.]{0,120}|IELTS[^.]{0,120})",t):
    print(m.group(1)[:160])
