# -*- 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"})
    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)
roots=["https://macss.uchicago.edu/","https://macss.uchicago.edu/admissions","https://macss.uchicago.edu/academics"]
for u in roots:
    try:
        st,h=get(u); t=clean(h)
        print("=== ",u,"status",st,"len",len(h),"text",len(t))
        print(t[:600]); print()
        # collect links
        links=sorted(set(re.findall(r'href="(/[^"#]+)"',h)))
        print("links:",[l for l in links if any(k in l for k in ["admiss","apply","curric","course","degree","tuition","cost","deadline","faq","career","requir","academics","program"])][:40])
        print()
    except Exception as e:
        print("ERR",u,repr(e)); print()
