# -*- coding: utf-8 -*-
import io, sys, os, re, ssl, json, 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=25):
    req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"})
    try:
        r = urllib.request.urlopen(req, timeout=timeout, context=ctx)
        b = r.read()
        return r.status, b.decode("utf-8", errors="replace")
    except Exception as e:
        return None, f"ERR {e}"

# 1. UVA records catalog 首页（Graduate）
for url in [
    "https://records.ureg.virginia.edu/content.php?catoid=44&navoid=3134",
    "https://records.ureg.virginia.edu/index.php",
]:
    st, body = get(url)
    print("==", url, "->", st, "len", len(body) if isinstance(body,str) else body)
    if st == 200 and isinstance(body, str):
        # 找研究生项目链接
        links = re.findall(r'href="([^"]*program[^"]*)"[^>]*>([^<]+)<', body, re.I)
        for l, t in links[:60]:
            print("  ", l, "|", t.strip()[:80])
