# -*- coding: utf-8 -*-
import io, sys, urllib.request, ssl, re, os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE

def probe(url, timeout=12):
    try:
        req=urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
        r=urllib.request.urlopen(req, timeout=timeout, context=ctx)
        b=r.read(); return r.status, len(b), b.decode("utf-8","ignore")
    except Exception as e:
        return None, 0, str(e)

cands = [
    ("UNC CS dept", "https://catalog.unc.edu/graduate/schools-departments/computer-science/"),
    ("UNC DS dept", "https://catalog.unc.edu/graduate/schools-departments/data-information-sciences/"),
    ("UNC BME dept", "https://catalog.unc.edu/graduate/schools-departments/biomedical-engineering/"),
    ("UNC CRP dept", "https://catalog.unc.edu/graduate/schools-departments/city-regional-planning/"),
    ("Rice MAI full", "https://csweb.rice.edu/academics/graduate-programs/master-artificial-intelligence"),
]
for name, url in cands:
    s, n, body = probe(url)
    print(f"\n=== [{name}] {s} {n}B ===")
    if s==200 and n>3000:
        text = re.sub(r"<script[\s\S]*?</script>","",body)
        text = re.sub(r"<style[\s\S]*?</style>","",text)
        text = re.sub(r"<[^>]+>"," ",text)
        text = re.sub(r"\s+"," ",text)
        # find degree requirements section
        print(text[:3500])
        links = re.findall(r'href="([^"]+)"', body)
        prog = [l for l in links if l.startswith("/graduate/") and not l.endswith("#programstext")]
        print("--- links ---")
        for l in sorted(set(prog))[:20]:
            print("  ", l)
