# -*- 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
UA = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36"}

def get(url, timeout=20):
    try:
        req = urllib.request.Request(url, headers=UA)
        r = urllib.request.urlopen(req, timeout=timeout, context=ctx)
        return r.status, r.read().decode("utf-8", errors="ignore")
    except Exception as e:
        return -1, str(e)

# UNC MHA 深挖
url = "https://catalog.unc.edu/graduate/schools-departments/health-policy-management/"
st, body = get(url)
print(f"=== UNC MHA: {st} {len(body)} ===")
# 找 MHA 详细段
idx = body.find("Master of Health Administration")
if idx > 0:
    txt = re.sub(r'<[^>]+>', ' ', body[idx:idx+2500])
    txt = h.unescape(re.sub(r'\s+', ' ', txt))
    print(txt[:1000])

# Vandy degree-programs.php
url2 = "https://gradschool.vanderbilt.edu/degree-programs.php"
st2, body2 = get(url2, timeout=15)
print(f"\n=== Vandy degree-programs: {st2} {len(body2)} ===")
if st2 == 200:
    # 找项目链接
    hrefs = re.findall(r'href="([^"]+)"', body2)
    prog = sorted(set([h for h in hrefs if "program" in h.lower() or "degree" in h.lower()]))
    print("program hrefs:", prog[:30])
