# -*- 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"})
    with urllib.request.urlopen(req,timeout=20,context=ctx) as r:
        return r.read().decode("utf-8","ignore")
def clean(t):
    t=re.sub(r"<script.*?</script>","",t,flags=re.S|re.I)
    t=re.sub(r"<style.*?</style>","",t,flags=re.S|re.I)
    t=re.sub(r"<[^>]+>"," ",t); t=html.unescape(t)
    t=re.sub(r"[ \t]+"," ",t); t=re.sub(r"\n\s*\n+","\n",t)
    return t.strip()

r=get("https://stat.uchicago.edu/academics/ms-in-statistics/statistics-masters-courses/")
c=clean(r)
print("==== courses 后半 ====")
print(c[3000:7000])

for u in ["https://physicalsciences.uchicago.edu/academics/application-requirements",
          "https://grad.uchicago.edu/admissions/tuition-financial-aid/",
          "https://stat.uchicago.edu/academics/ms-in-statistics/"]:
    try:
        r2=get(u); print("\n========",u,"len=",len(r2))
        cc=clean(r2)
        # 抓含 tuition / fee / TOEFL / IELTS / GRE / credit / course 的行
        for line in cc.split("\n"):
            if re.search(r"tuition|fee|TOEFL|IELTS|Duolingo|GRE|credit|course hour|quarter|GPA|3\.|90|100|7\.0",line,re.I):
                print("  ·",line[:220])
    except Exception as e:
        print(u,"ERR",repr(e))
