# -*- 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=25):
    req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
    r = urllib.request.urlopen(req, timeout=timeout, context=ctx)
    return r.status, r.read().decode("utf-8", errors="replace")

st, body = get("https://catalog.unc.edu/graduate/degree-programs/")
print("status", st, "len", len(body))
# 项目链接通常形如 /graduate/degree-programs/xxx/
links = re.findall(r'href="(/graduate/degree-programs/[^"#]+)"[^>]*>([^<]+)</a>', body)
seen=set()
for href,t in links:
    t=h.unescape(t).strip()
    if href in seen: continue
    seen.add(href)
    if not t or t in ["Programs A-Z"]: continue
    print(" ", href, "|", t[:90])
