# -*- 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"})
    d=urllib.request.urlopen(req,context=ctx,timeout=20).read().decode("utf-8","ignore")
    return d
d=get("https://masters.cs.uchicago.edu/academics/")
links=re.findall(r'href="([^"]+)"',d)
for x in sorted({x for x in links if "masters.cs.uchicago.edu" in x and any(k in x for k in ["course","specialization","streamline","9-","12-","practicum","internship"]) }):
    print(x)
print("\n=== prospective-students ===")
try:
    p=get("https://masters.cs.uchicago.edu/prospective-students/")
    h=re.sub(r"<script.*?</script>"," ",p,flags=re.S|re.I); h=re.sub(r"<style.*?</style>"," ",h,flags=re.S|re.I)
    t=re.sub(r"<[^>]+>"," ",h); t=re.sub(r"&nbsp;|&#x27;|&amp;|&#8217;|&#038;|&#8203;|&#8211;|&#039;"," ",t); t=re.sub(r"\s+"," ",t)
    pl=sorted({x for x in re.findall(r'href="([^"]+)"',p) if any(k in x for k in ["admiss","deadline","requir","tuition","fees","gre","toefl","application","faq","tuition"])})
    print("links:",pl)
    print(t[:1800])
except Exception as e:
    print("FAIL",repr(e)[:100])
