# -*- 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 = [
    ("Rice engineering grad", "https://engineering.rice.edu/academics/graduate-programs"),
    ("Rice eng cs", "https://csweb.rice.edu/academics/graduate-programs"),
    ("Rice ece", "https://eece.rice.edu/academics/graduate-programs"),
    ("Brown gradschool A-Z", "https://graduateschool.brown.edu/academics/degree-programs"),
    ("Brown grad A-Z v2", "https://graduateschool.brown.edu/academics"),
    ("UVA records", "https://records.ureg.virginia.edu/index.php"),
    ("UVA catalog grad", "https://records.ureg.virginia.edu/index.php-level-group=Graduate%20School"),
    ("UNC grad catalog", "https://catalog.unc.edu/graduate/"),
    ("Vandy grad catalog", "https://catalog.vanderbilt.edu/graduate/"),
    ("ND grad catalog", "https://graduateschool.nd.edu/academics/degrees"),
]
for name, url in cands:
    s, n, body = probe(url)
    print(f"[{name}] {s} {n}B")
    if s==200 and n>5000:
        # extract links
        links = re.findall(r'href="([^"]+)"', body)
        prog_links = [l for l in links if re.search(r'(graduate|master|ms|m\.s|program|degree)', l, re.I) and l.startswith("/") and not l.endswith(".pdf")]
        for l in prog_links[:15]:
            print("   ", l)
