# -*- 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/ENERGY-MS"
req=urllib.request.Request(url,headers={"User-Agent":"Mozilla/5.0"})
txt=urllib.request.urlopen(req,context=ctx,timeout=25).read().decode("utf-8","ignore")
t=re.sub(r"<script[\s\S]*?</script>","",txt)
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")
j=t.find("Program Policies",i)
print(t[i:j if j>i else i+4000])
print("\n===== 关键词 =====")
for kw in ["track","concentration","two degree","49 units","45 units","GPA","quarterly","prerequisite","online","part-time","HCP","Coterminal","thesis","research","advisor","proposal","STEM"]:
    k=t.lower().find(kw.lower())
    if k>=0:
        print(f"[{kw}] ...{t[max(0,k-90):k+180]}...")
