# -*- coding: utf-8 -*-
import io,sys,urllib.request,ssl,re
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
url="https://bulletin.stanford.edu/programs/APLPH-MS"
req=urllib.request.Request(url,headers={"User-Agent":"Mozilla/5.0"})
raw=urllib.request.urlopen(req,context=ctx,timeout=25).read().decode("utf-8","ignore")
t=re.sub(r"<script[\s\S]*?</script>","",raw)
t=re.sub(r"<style[\s\S]*?</style>","",t)
t=re.sub(r"<[^>]+>"," ",t)
t=re.sub(r"&nbsp;"," ",t); t=re.sub(r"&amp;","&",t); t=re.sub(r"\s+"," ",t)
for kw in ["Humanities","School of","department","33 units","Directed Studies","seminar","Proposal","Completion","two year","quarter","residence"]:
    for m in re.finditer(re.escape(kw),t,re.I):
        k=m.start(); print(f"[{kw}] ...{t[max(0,k-70):k+160]}..."); break
# 头部 title/school
print("\nHEAD:", t[:260])
