# -*- coding: utf-8 -*-
import ssl,urllib.request,re,io,sys
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 get(u):
    req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
    with urllib.request.urlopen(req,context=ctx,timeout=20) as r:
        return r.read().decode("utf-8","ignore")
# 学费页
t=get("https://graduate.dartmouth.edu/admissions-financial-aid/tuition-living-costs")
txt=re.sub(r"<script.*?</script>","",t,flags=re.S); txt=re.sub(r"<style.*?</style>","",txt,flags=re.S)
txt=re.sub(r"<[^>]+>"," ",txt); txt=re.sub(r"\s+"," ",txt).strip()
print("=== 学费页 $ 上下文 ===")
for m in re.finditer(r"\$[\d,]+",txt):
    s=max(0,m.start()-120); e=min(len(txt),m.end()+120); print(txt[s:e]); print("---")
for kw in ["Master","master","tuition","Tuition","per term","per term","stipend","health","fee"]:
    mm=re.search(kw,txt)
    if mm:
        s=max(0,mm.start()-100); e=min(len(txt),mm.end()+200); print("["+kw+"]",txt[s:e])
# 系站 masters 链接
t2=get("https://web.cs.dartmouth.edu/graduate/apply-graduate-programs")
print("=== 系站 masters 链接 ===")
for h in re.findall(r'href="([^"]+)"',t2):
    if "master" in h.lower() or "digital" in h.lower() or "4+1" in h.lower():
        print(h)
