# -*- coding: utf-8 -*-
import io,sys,ssl,urllib.request,re,html
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"})
    return urllib.request.urlopen(req,timeout=20,context=ctx).read().decode("utf-8","ignore")
u="https://bulletin.stanford.edu/programs/CS-MS"
t=get(u)
c=html.unescape(re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",re.sub(r"<script.*?</script>"," ",t,flags=re.S))))
def seg(a,b=None,n=1600):
    j=c.find(a)
    if j<0: print("NOT FOUND",a); return
    k=c.find(b,j+len(a)) if b else j+n
    print("----",a,"----")
    print(c[j:k if k>0 else j+n])
seg("Program Overview","Program Policies")
seg("Requirements Overview","Learning Outcomes")
seg("Minimum Units in the Program")
# 方向/option 关键词
for kw in ["track","option","concentration","specialization","systems","theory","artificial intelligence","human-computer","computer security","biocomputation","graphical"]:
    j=c.lower().find(kw.lower())
    if j>=0: print(f"[{kw}] {c[max(0,j-40):j+120]}")
