# -*- 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=12):
    try:
        req=urllib.request.Request(u, headers=hdr)
        with urllib.request.urlopen(req, timeout=timeout, context=ctx) as r:
            return r.status, r.read(250000).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)[:50]}"

print("===== unc-stor 系站 =====")
for u in ["https://stor.unc.edu/","https://stor.unc.edu/graduate/"]:
    st,body,err=fetch(u)
    print(f"-- {u} http={st} {err} len={len(body)}")
    if st==200:
        txt=re.sub(r'<[^>]+>',' ',body); txt=re.sub(r'\s+',' ',txt)
        for m in re.finditer(r'.{80}(GRE|GMAT|tuition|\$\s?[0-9,]{3,}|per credit|per unit).{80}', txt):
            s=m.group(0)
            if "GREK" in s: continue
            print("  >>", s[:200])
        # 链接到项目/招生页
        for a in re.findall(r'href="([^"]*(admission|graduate|program|master|tuition|fee)[^"]*)"', body, re.I)[:12]:
            print("  link:", a)

print("\n===== berkeley-grad 研究生院 =====")
for u in ["https://grad.berkeley.edu/","https://grad.berkeley.edu/admissions/apply/","https://grad.berkeley.edu/financial-support/cost-attendance/"]:
    st,body,err=fetch(u)
    print(f"-- {u} http={st} {err} len={len(body)}")
    if st==200:
        txt=re.sub(r'<[^>]+>',' ',body); txt=re.sub(r'\s+',' ',txt)
        for m in re.finditer(r'.{70}(GRE|GMAT|tuition|\$\s?[0-9,]{3,}|per unit|per semester).{70}', txt):
            print("  >>", m.group(0)[:190])
