# -*- 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")
t=get("https://bulletin.stanford.edu/programs/CS-MS")
c=html.unescape(re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",re.sub(r"<script.*?</script>"," ",t,flags=re.S))))
# Foundations 区域名
for m in re.finditer(r"(Logic, Automata[^A-Z]{0,60}|Probability|Computer Organization and Systems|Principles of Computer Systems|Data Structures|Algorithms|Mathematical Foundations)",c):
    print("FOUND:",m.group(1)[:70])
# subplans 行
j=c.find("subplans")
if j<0: j=c.find("Artificial Intelligence")
print("\nSUBPLANS:\n",c[j-120:j+400])
# coterminal / joint / online 提及
for kw in ["coterminal","coterm","joint","online","distance","part-time","terminal professional","with distinction in research"]:
    i=c.lower().find(kw)
    if i>=0: print(f"[{kw}] {c[max(0,i-50):i+150]}")
