# -*- 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/programs/computer-science")
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()
# 去导航：找主内容起点
for kw in ["Master","PhD","M.S.","degree","Degree","deadline","Deadline","GRE","TOEFL","IELTS","tuition","Tuition","GPA","admission","Admission","residence","program","Program"]:
    for m in re.finditer(kw,txt):
        s=max(0,m.start()-140); e=min(len(txt),m.end()+220)
        print("["+kw+"]",txt[s:e]); break
print("="*80); print("TAIL"); print(txt[-2600:])
