# -*- coding: utf-8 -*-
import io,sys,ssl,urllib.request,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://harris.uchicago.edu/academics/programs-degrees/degrees/ms-computational-analysis-and-public-policy-mscapp"
req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"})
with urllib.request.urlopen(req,timeout=25,context=ctx) as r:
    html=r.read().decode("utf-8","replace")
t=re.sub(r"<script[\s\S]*?</script>","",html)
t=re.sub(r"<style[\s\S]*?</style>","",t)
t=re.sub(r"<[^>]+>"," ",t); t=re.sub(r"\s+"," ",t)
# locate main body after the second occurrence of MSCAPP description
kw=["credit","track","STEM","internship","capstone","duration","quarter","GRE","TOEFL","IELTS","Duolingo","deadline","tuition","fee","scholarship","admission","prerequisite","recommend","letter","statement","resume","full-time","two-year","one-year","21-month","specializ","concentration","rank"]
sents=re.split(r"(?<=[.。;])\s+", t)
seen=set()
for s in sents:
    sl=s.lower()
    if any(k.lower() in sl for k in kw) and len(s)>25:
        if s not in seen:
            seen.add(s); print("-",s[:400])
print("\n=== links ===")
for m in re.findall(r'href="([^"]+)"',html):
    if any(x in m.lower() for x in ["deadline","require","admiss","tuition","cost","apply","curricul","financ","intern","outcome","international","english"]):
        print(m)
