# -*- 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)
i=t.find("Requirements Overview")
if i<0: i=t.find("Requirements")
print(t[i:i+3000])
print("\n===== 其余关键词 =====")
for kw in ["full time","part time","online","coterminal","prerequisite","background","advisor","proposal","completion","units of","seminar","breadth","depth","core"]:
    k=t.lower().find(kw.lower())
    if k>=0: print(f"[{kw}] ...{t[max(0,k-80):k+170]}...")
