# -*- coding: utf-8 -*-
import io, sys, os, re, ssl, urllib.request, html as h
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 get(url, timeout=20):
    req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
    try:
        r = urllib.request.urlopen(req, timeout=timeout, context=ctx)
        b = r.read()
        return r.status, len(b), b.decode("utf-8", errors="replace")
    except Exception as e:
        return None, 0, f"ERR {type(e).__name__}"

slugs = [
    "applied-data-science",
    "statistics-analytics-and-data-science",
    "biomedical-and-health-informatics",
    "data-science",
    "computer-science",
    "bioinformatics-and-computational-biology",
    "statistics",
    "economics",
    "business-administration",
    "accounting",
]
for s in slugs:
    for prefix in ["graduate/degree-programs", "academic-programs", "schools-departments/data-information-sciences"]:
        url = f"https://catalog.unc.edu/{prefix}/{s}/"
        st, n, body = get(url, timeout=12)
        if st == 200 and n > 5000:
            title = re.search(r"<title>([^<]+)</title>", body, re.I)
            print(f"OK {st} {n:>7}  {url}")
            print("   title:", h.unescape(title.group(1).strip())[:100] if title else "?")
            break
    else:
        # 试第一个失败的
        print(f"-- {st} {n:>7}  {url}")
