# -*- 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):
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
        with urllib.request.urlopen(req,timeout=25,context=ctx) as r:
            return r.status,r.read().decode("utf-8","replace")
    except Exception as e:
        return None,str(e)
def body(h):
    h=re.sub(r"<script[\s\S]*?</script>","",h); h=re.sub(r"<style[\s\S]*?</style>","",h)
    m=re.search(r"<main[\s\S]*?</main>",h); seg=m.group(0) if m else h
    seg=re.sub(r"<[^>]+>"," ",seg); return re.sub(r"\s+"," ",seg)
st,h=get("https://pme.uchicago.edu/admissions/master-engineering-admissions/faqs")
if st==200:
    t=body(h); i=t.find("Program FAQs"); print("### FAQ"); print(t[i:i+2200] if i>=0 else t[:2200]); print()
for u in ["https://grad.uchicago.edu/admissions/apply/english-language-requirements/",
          "https://grad.uchicago.edu/admissions/apply/required-scores/"]:
    st,h=get(u); print("="*12,u,st,(len(h) if isinstance(h,str) else h))
    if isinstance(h,str) and st==200:
        t=body(h)
        for kw in ["TOEFL","IELTS","100","7.0","minimum","score","Duolingo"]:
            j=t.lower().find(kw.lower())
            if j>=0: print("  -",kw,"::",t[max(0,j-60):j+150])
