# -*- coding: utf-8 -*-
import urllib.request, ssl, sys, io, re, json, os
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}
def get(url):
    req = urllib.request.Request(url, headers=UA)
    return urllib.request.urlopen(req, timeout=20, context=SCTX).read().decode("utf-8","ignore")
def strip(h):
    h = re.sub(r"<script[\s\S]*?</script>", " ", h, flags=re.I)
    h = re.sub(r"<style[\s\S]*?</style>", " ", h, flags=re.I)
    h = re.sub(r"<[^>]+>", " ", h); h = re.sub(r"\s+"," ", h)
    return h.strip()
items = [
  ("unc-mpp", "https://catalog.unc.edu/graduate/schools-departments/public-policy/"),
  ("nyu-french", "https://bulletins.nyu.edu/graduate/arts-science/programs/french-studies-ma/"),
  ("nyu-italian", "https://bulletins.nyu.edu/graduate/arts-science/programs/italian-studies-ma/"),
  ("nyu-lac", "https://bulletins.nyu.edu/graduate/arts-science/programs/latin-american-caribbean-studies-ma/"),
  ("nyu-near", "https://bulletins.nyu.edu/graduate/arts-science/programs/near-eastern-studies-ma/"),
]
out = {}
for tag, url in items:
    text = strip(get(url))
    print(f"\n========== {tag} ==========")
    print(f"len={len(text)}")
    for kw in ["Master of Arts", "Master of Public", "MPP", "Program Requirements", "credit", "thesis", "exam", "language", "Elective", "Course List"]:
        i = text.lower().find(kw.lower())
        if i>=0:
            print(f"\n[{kw}] ...{text[max(0,i-80):i+350]}...")
    out[tag] = {"url": url, "text": text[:4000]}
json.dump(out, open("_round75_data.json","w",encoding="utf-8"), ensure_ascii=False, indent=2)
print("\nSaved _round75_data.json")
