import re, sys, io, urllib.request, ssl
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(url):
    req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
    with urllib.request.urlopen(req, timeout=12, context=ctx) as resp:
        return resp.status, resp.read().decode("utf-8","ignore")
def clean(b):
    t=re.sub(r'<script[\s\S]*?</script>','',b); t=re.sub(r'<style[\s\S]*?</style>','',t)
    t=re.sub(r'<[^>]+>',' ',t); return re.sub(r'\s+',' ',t)

# Illinois catalog MSPE
st,body=get("https://catalog.illinois.edu/graduate/las/policy-economics-ms")
t=clean(body)
print("=== Illinois MSPE catalog ===")
for kw in ["GRE","GMAT","test","Test"]:
    for m in re.finditer(r'[^.]*'+kw+r'[^.]*\.?', t):
        print("  -", m.group(0).strip()[:170])
links=dict.fromkeys(re.findall(r'href="([^"]+)"',body))
for l in links:
    if "admiss" in l.lower() or "admission" in l.lower():
        print("  adm link:", l)
print()

# UW MDSAI 找 admission/requirement 链接与 test
for k,u in [("UW-MDSAI","https://uwaterloo.ca/future-graduate-students/programs/by-faculty/math/data-science-and-artificial-intelligence-co-op-master-data"),
            ("UW-ECE","https://uwaterloo.ca/future-graduate-students/programs/by-faculty/engineering/electrical-and-computer-engineering-co-op-master-engineering"),
            ("Geo","https://bioinformatics.georgetown.edu/")]:
    st,body=get(u); t=clean(body)
    print(f"=== {k} ===")
    for m in re.finditer(r'[^.]*\b(GRE|GMAT)\b[^.]*\.?', t, re.I):
        print("  -", m.group(0).strip()[:160])
    al=dict.fromkeys(re.findall(r'href="([^"]+)"',body))
    for l in al:
        if any(x in l.lower() for x in ["admiss","requirement","how-to-apply"]):
            print("  link:", l)
    print()
