import re, 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
def probe(url):
    try:
        req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
        with urllib.request.urlopen(req, timeout=12, context=ctx) as resp:
            return resp.status, resp.read().decode("utf-8","ignore")
    except urllib.error.HTTPError as e: return e.code, ""
    except Exception as e: return "ERR", str(e)[:50]
def clean(b):
    t=re.sub(r'<script[\s\S]*?</script>','',b); t=re.sub(r'<style[\s\S]*?</style>','',t)
    t=re.sub(r'<[^>]+>',' ',t); return re.sub(r'\s+',' ',t)

# UW compmath 项目页找 math admission 链接
st,body=probe("https://uwaterloo.ca/future-graduate-students/programs/by-faculty/mathematics/computational-mathematics-co-op-master-mathematics-mmath")
print("=== UW compmath 项目页", st, len(body),"===")
al=dict.fromkeys(re.findall(r'href="([^"]+)"',body))
for l in al:
    if any(x in l.lower() for x in ["admission","requirement","graduat"]):
        print("  link:", l)

pages=[
 ("UW-math-req","https://uwaterloo.ca/math/graduate-studies/admission-requirements"),
 ("McGill-MMA-adm","https://www.mcgill.ca/desautels/master-management-analytics/admission-requirements"),
 ("WUSTL-grad-test","https://gradadmissions.washu.edu/applying-to-washu/"),
 ("JHU-cat-fin","https://e-catalogue.jhu.edu/business/degrees-certificates/finance-master-science/"),
]
for k,u in pages:
    st,body=probe(u)
    print(f"\n=== {k} HTTP {st} len {len(body)} ===")
    if st==200:
        t=clean(body); hits=0
        for m in re.finditer(r'[^.]*\b(GRE|GMAT)\b[^.]*\.?', t, re.I):
            print("  -", m.group(0).strip()[:170]); hits+=1
            if hits>=3: break
        if hits==0: print("  (无 GRE/GMAT 字样)")
