# -*- 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__}: {e}"

# Brown / Rice / Vandy catalog 探测
candidates = [
    ("Brown catalog", "https://catalog.brown.edu/"),
    ("Brown grad", "https://graduateschool.brown.edu/"),
    ("Brown programs", "https://graduate.brown.edu/degree-programs"),
    ("Rice grad", "https://ga.rice.edu/"),
    ("Rice catalog", "https://courses.rice.edu/"),
    ("Vandy grad", "https://gradschool.vanderbilt.edu/"),
    ("Vandy catalog", "https://bulletin.vanderbilt.edu/"),
]
for name, url in candidates:
    st, n, body = get(url)
    print(f"{name:18s} {st} {n:>8}  {url}")
    if st == 200 and n > 3000:
        title = re.search(r"<title>([^<]+)</title>", body, re.I)
        print("   title:", h.unescape(title.group(1).strip())[:100] if title else "?")
