# -*- 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)

u="https://codas.uchicago.edu/academics/ms-data-science/"
t,n=get(u); print("CODAS MS DS",u,"len=",n)
if not t.startswith("ERR"):
    for h in sorted(set(re.findall(r'href="([^"]+)"',t))):
        if any(k in h.lower() for k in ["admiss","apply","tuition","curric","faq","deadline","requir"]):
            print("  href:",h)
    print("-"*60)
    print(clean(t)[:2600])

print("="*80)
u2="https://datascience.uchicago.edu/education/masters-programs/masters-in-applied-ai/"
t2,n2=get(u2); print("Applied AI",u2,"len=",n2)
if not t2.startswith("ERR"):
    for h in sorted(set(re.findall(r'href="([^"]+)"',t2))):
        if any(k in h.lower() in h for k in []): pass
    for h in sorted(set(re.findall(r'href="([^"]+)"',t2))):
        if any(k in h.lower() for k in ["applied-ai","appliedai","applied_ai"]):
            print("  href:",h)
    c2=clean(t2)
    # 找正文主体：去掉导航，抓 "Applied Artificial Intelligence" 之后
    i=c2.find("MS in Applied Artificial Intelligence")
    print("-"*60)
    print(c2[i:i+2200] if i>=0 else c2[:2200])
