# -*- 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"})
        b=urllib.request.urlopen(req,timeout=20,context=ctx).read()
        return b.decode("utf-8","ignore"),len(b)
    except Exception as e:
        return "ERR "+repr(e),0
def clean(t):
    t=re.sub(r"<script.*?</script>"," ",t,flags=re.S)
    t=re.sub(r"<style.*?</style>"," ",t,flags=re.S)
    t=re.sub(r"<[^>]+>"," ",t); return re.sub(r"\s+"," ",t)
P="https://datascience.uchicago.edu/education/masters-programs/masters-in-applied-artificial-intelligence/"
t,n=get(P)
links=set(re.findall(r'href="([^"]+)"',t))
for l in sorted(links):
    if "application" in l.lower() or "process" in l.lower():
        print("LINK",l)
# 申请流程页
for cand in ["application-process/","how-to-apply/","admissions/"]:
    tt,nn=get(P+cand)
    print("="*60,cand,nn)
    if not tt.startswith("ERR"):
        c=clean(tt)
        for kw in ["deadline","Deadline","Round","November","December","January","February","March","April","May","TOEFL","IELTS","minimum","recommend","application fee","fee","recommendation","statement","resume","CV","transcript","GRE"]:
            j=c.find(kw)
            if j>=0: print(f"  [{kw}] ...{c[max(0,j-60):j+150]}...")
