# -*- coding: utf-8 -*-
import io, sys, os, re, ssl, urllib.request
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__}: {e}"

candidates = [
    ("UCSD grad", "https://grad.ucsd.edu/"),
    ("UCSD catalog", "https://catalog.ucsd.edu/"),
    ("UCSD grad programs", "https://grad.ucsd.edu/programs/index.html"),
    ("UCSD catalog grad", "https://catalog.ucsd.edu/front/grad.html"),
    # UNC catalog
    ("UNC catalog", "https://catalog.unc.edu/"),
    ("UNC catalog grad", "https://catalog.unc.edu/graduate/"),
    # UVA catalog
    ("UVA catalog", "https://records.ureg.virginia.edu/index.php"),
    # 兜底：GaTech 是否还有 MS 剩余
    ("GaTech prog", "https://catalog.gatech.edu/programs/"),
]
for name, url in candidates:
    st, n, body = get(url)
    print(f"{name:20s} {st} {n:>8}  {url}")
    if st == 200 and isinstance(body,str) and len(body) > 2000:
        title = re.search(r"<title>([^<]+)</title>", body, re.I)
        print("   title:", title.group(1).strip()[:100] if title else "?")
