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

pages = {
 "nu-mlds":"https://www.mccormick.northwestern.edu/machine-learning-data-science/admission-requirements/",
 "rice-mai":"https://csweb.rice.edu/academics/graduate-programs/master-artificial-intelligence",
 "dartmouth-mem":"https://engineering.dartmouth.edu/academics/graduate/mem/",
 "dartmouth-meng":"https://engineering.dartmouth.edu/graduate/meng",
 "vandy-biostat":"https://www.vanderbilt.edu/biostatistics-graduate/master-of-science/",
 "ubc-mj":"https://jwam.ubc.ca/graduate/admissions/",
}

def fetch(u):
    try:
        req=urllib.request.Request(u, headers=hdr)
        with urllib.request.urlopen(req, timeout=15, context=ctx) as r:
            return r.status, r.read(300000).decode("utf-8","ignore")
    except Exception as e:
        return None, str(e)[:100]

for tid,u in pages.items():
    st,body=fetch(u)
    print(f"===== [{tid}] http={st} =====")
    if st!=200:
        print("  ", body[:100]); continue
    hits=re.findall(r'.{0,90}(GRE|GMAT).{0,90}', body, re.I)
    if not hits:
        print("   正文无 GRE/GMAT 字样")
    for h in hits[:6]:
        print("   -", re.sub(r'\s+',' ',h)[:170])
