# -*- 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()

for u in ["https://stat.uchicago.edu/academics/ms-in-statistics/",
          "https://stat.uchicago.edu/academics/ms-in-statistics/admission-requirements/"]:
    raw=get(u)
    print("\n============",u,"len=",len(raw))
    print(clean(raw)[:4500])
