# -*- 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=20):
    req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
    try:
        r = urllib.request.urlopen(req, timeout=timeout, context=ctx)
        return r.status, r.read().decode("utf-8", errors="replace")
    except Exception as e:
        return None, f"ERR {type(e).__name__}"

st, body = get("https://www.brown.edu/academics/")
# 提取所有内部链接
links = re.findall(r'href="(/[^"]*)"[^>]*>([^<]+)</a>', body)
seen = {}
for href, t in links:
    t = h.unescape(t).strip()
    if not t or len(t) < 3: continue
    if href not in seen:
        seen[href] = t

# 筛研究生项目相关
for href, t in sorted(seen.items()):
    low = (href + " " + t).lower()
    if any(k in low for k in ["graduate","master","phd","ph.d","sc.m","ma","ms","degree"]):
        if any(k in low for k in ["computer","data","econom","biolog","engineer","statistic","math","physic","business","manage","financ","applied","computational","bio","health","public","internation","science","human","soc","policy","design","art","music","edu"]):
            print(" ", href, "|", t[:80])
