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

url = "https://graduateschool.brown.edu/index.php/academics/programs-requirements"
req = urllib.request.Request(url, headers=UA)
r = urllib.request.urlopen(req, timeout=20, context=ctx)
body = r.read().decode("utf-8", errors="ignore")

# 找所有 href
hrefs = re.findall(r'href="([^"]+)"', body)
# 过滤含 academics 的
acad = sorted(set([h for h in hrefs if "academics" in h or "program" in h.lower()]))
print("academics/program hrefs:")
for h in acad[:50]:
    print(" -", h)
print("---")
# 找 Fields of Study 段
idx = body.find("Fields of Study")
if idx > 0:
    print(body[idx:idx+3000])
