# -*- coding: utf-8 -*-
import io, sys, os, re, json, 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)
        b = r.read(); return r.status, b.decode("utf-8", errors="ignore")
    except Exception as e:
        return -1, str(e)

# Brown graduateschool programs-requirements 列表页
url = "https://graduateschool.brown.edu/index.php/academics/programs-requirements"
st, body = get(url)
print("LIST:", st, len(body))

# 提取所有 /academics/programs-requirements/<slug>/ 链接
slugs = re.findall(r'href="(/academics/programs-requirements/[^"]+)"', body)
slugs = sorted(set([s.split("/")[-2] if s.endswith("/") else s.split("/")[-1] for s in slugs]))
print("slugs:", len(slugs))
for s in slugs[:60]:
    print(" -", s)
