# -*- coding: utf-8 -*-
import urllib.request, ssl, io, sys, os, re, json
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
SCTX = ssl.create_default_context(); SCTX.check_hostname=False; SCTX.verify_mode=ssl.CERT_NONE
UA = {"User-Agent":"Mozilla/5.0"}

targets = [
    ("cyber", "https://bulletins.nyu.edu/graduate/engineering/programs/cybersecurity-ms/"),
    ("ie", "https://bulletins.nyu.edu/graduate/engineering/programs/industrial-engineering-ms/"),
    ("biotech", "https://bulletins.nyu.edu/graduate/engineering/programs/biotechnology-ms/"),
    ("constr", "https://bulletins.nyu.edu/graduate/engineering/programs/construction-management-ms/"),
    ("idm", "https://bulletins.nyu.edu/graduate/engineering/programs/integrated-design-media-ms/"),
]
data = {}
for key, url in targets:
    req = urllib.request.Request(url, headers=UA)
    r = urllib.request.urlopen(req, timeout=15, context=SCTX)
    body = r.read().decode("utf-8", errors="ignore")
    # 提取 main content 段
    m = re.search(r'<main[^>]*>([\s\S]*?)</main>', body)
    txt = m.group(1) if m else body
    # 去掉 tag
    txt = re.sub(r'<script[\s\S]*?</script>', '', txt)
    txt = re.sub(r'<style[\s\S]*?</style>', '', txt)
    txt = re.sub(r'<[^>]+>', ' ', txt)
    txt = re.sub(r'\s+', ' ', txt).strip()
    # 找关键段
    data[key] = txt[:4000]
    print(f"=== {key} ({len(txt)} chars) ===")
    print(txt[:1500])
    print()
json.dump(data, open("_round72_data.json","w",encoding="utf-8"), ensure_ascii=False, indent=2)
