# -*- coding: utf-8 -*-
import re, os, sys, io, urllib.request, ssl, socket
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
ctx = ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
hdr={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36"}
def fetch(u, timeout=15):
    try:
        req=urllib.request.Request(u, headers=hdr)
        with urllib.request.urlopen(req, timeout=timeout, context=ctx) as r:
            return r.status, r.read(300000).decode("utf-8","ignore"), ""
    except urllib.error.HTTPError as e: return None,"",f"HTTP {e.code}"
    except Exception as e: return None,"",f"{type(e).__name__} {str(e)[:60]}"

cases = [
 ("unc-mcrp","https://catalog.unc.edu/graduate/schools-departments/city-regional-planning/"),
 ("nyu-applied-stat","https://steinhardt.nyu.edu/degree/ms-applied-statistics-social-science-research/"),
]
for tid,u in cases:
    st,body,err=fetch(u)
    print("="*70)
    print(f"[{tid}] http={st} {err}")
    if st!=200: continue
    txt=re.sub(r'<[^>]+>',' ',body)
    txt=re.sub(r'\s+',' ',txt)
    for m in re.finditer(r'.{180}(GRE|GMAT).{180}', txt):
        seg=m.group(0)
        if "GREK" in seg: continue
        print("  >>", seg[:380])
        print("  ---")
    # 学费数字
    for m in re.finditer(r'.{60}(\$\s?[0-9,]{3,}).{40}', txt):
        print("  $:", m.group(0)[:150])
