# -*- 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
u="https://bulletin.stanford.edu/programs/SYMBO-MS"
req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
try:
    raw=urllib.request.urlopen(req,timeout=20,context=ctx).read()
    print("bytes=",len(raw))
    t=raw.decode("utf-8","ignore")
    c=html.unescape(re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",re.sub(r"<script.*?</script>"," ",t,flags=re.S))))
    for kw in ["Master of Science","degree requirements","units","Breadth","Depth","track","concentration","thesis","GPA","prerequisite","online","part-time","STEM","fellowship","assistantship"]:
        i=c.lower().find(kw.lower())
        if i>=0:
            print("\n###",kw,"@",i,"\n",c[i:i+380])
except Exception as e:
    print("ERR",type(e).__name__,e)
