# -*- coding: utf-8 -*-
import urllib.request, ssl, sys, io, re
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
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=15, 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()

# UNC Economics
text = strip(get("https://catalog.unc.edu/graduate/schools-departments/economics/"))
print("===== UNC Economics =====")
print("len=", len(text))
for kw in ["Master of Arts", "MA", "Ph.D.", "doctoral", "terminal", "degree"]:
    i = text.lower().find(kw.lower())
    if i>=0:
        print(f"\n[{kw}] ...{text[max(0,i-120):i+300]}...")

# NYU GSAS 剩余 slug 探活
print("\n===== NYU GSAS slugs =====")
slugs = [
    "french-studies-ma","italian-studies-ma","german-studies-ma",
    "russian-studies-ma","slavic-studies-ma","hebrew-and-judaic-studies-ma",
    "religion-ma","anthropology-ma","linguistics-ma",
    "music-ma","philosophy-ma","art-archaeology-ma",
    "near-eastern-studies-ma","middle-eastern-studies-ma",
    "latin-american-caribbean-studies-ma","european-mediterranean-studies-ma",
    "environmental-studies-ma","science-and-society-ma",
    "mathematics-ma","physics-ma","chemistry-ma","biology-ma",
]
for slug in slugs:
    url = f"https://bulletins.nyu.edu/graduate/arts-science/programs/{slug}/"
    try:
        req = urllib.request.Request(url, headers=UA)
        r = urllib.request.urlopen(req, timeout=10, context=SCTX)
        print(f"  {slug:40s} {r.status} {len(r.read())}")
    except Exception as e:
        print(f"  {slug:40s} ERR {str(e)[:50]}")
