# -*- 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
u="https://ga.rice.edu/programs-study/departments-programs/engineering/computer-science"
req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
raw=urllib.request.urlopen(req,context=ctx,timeout=25).read().decode("utf-8","ignore")
tt=re.sub(r"<script[\s\S]*?</script>","",raw)
tt=re.sub(r"<style[\s\S]*?</style>","",tt)
tt=re.sub(r"<[^>]+>"," ",tt)
tt=re.sub(r"&nbsp;"," ",tt); tt=re.sub(r"&amp;","&",tt); tt=re.sub(r"&#8203;","",tt); tt=re.sub(r"\s+"," ",tt)
# 找 Graduate 段标题后正文
for m in re.finditer(r"Graduate", tt):
    k=m.start()
    seg=tt[k:k+200]
    if "MCS" in seg or "Master" in seg or "credit" in seg.lower() or "hour" in seg.lower():
        print(f"@{k}: {seg}\n")
# 学分要求关键词
for kw in ["30 hours","36 hours","30 credit","36 credit","core course","elective","capstone","research","thesis","GPA","full-time","on-premise","online","online option"]:
    k=tt.lower().find(kw.lower())
    if k>=0: print(f"[{kw}] ...{tt[max(0,k-100):k+260]}...\n")
