# -*- coding: utf-8 -*-
import urllib.request, ssl, re, io, sys, 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

def fetch(url):
    req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
    r = urllib.request.urlopen(req, timeout=20, context=SCTX)
    return r.read().decode("utf-8", errors="replace")

# Dump NYU Math page structure
html = fetch("https://bulletins.nyu.edu/graduate/arts-science/programs/mathematics-ms/")
# Remove tags, get text
text = re.sub(r"<script[\s\S]*?</script>", "", html)
text = re.sub(r"<style[\s\S]*?</style>", "", text)
text = re.sub(r"<[^>]+>", " ", text)
text = re.sub(r"\s+", " ", text)
# Find key sections
for kw in ["Master of Science", "Degree Requirements", "Admission", "Application", "Prerequisite", "Credit", "Graduate School", "Deadline", "Tuition", "Financial"]:
    idx = text.lower().find(kw.lower())
    if idx >= 0:
        print(f"--- {kw} @ {idx} ---")
        print(text[max(0,idx-50):idx+300])
        print()
