# -*- 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
def get(u):
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
        resp=urllib.request.urlopen(req,context=ctx,timeout=20)
        d=resp.read().decode("utf-8","ignore")
        h=re.sub(r"<script.*?</script>"," ",d,flags=re.S|re.I); h=re.sub(r"<style.*?</style>"," ",h,flags=re.S|re.I)
        t=re.sub(r"<[^>]+>"," ",h); t=re.sub(r"&nbsp;|&#x27;|&amp;|&#8217;|&#038;|&#8203;|&#8211;|&#039;"," ",t); t=re.sub(r"\s+"," ",t)
        return resp.status,len(t),t
    except Exception as e:
        return "ERR",type(e).__name__,str(e)[:120]
for u in ["https://datascience.uchicago.edu/education/masters-programs/in-person-program/",
          "https://datascience.uchicago.edu/how-to-apply/"]:
    st,n,t=get(u); print("="*20,u,"STATUS",st,"LEN",n)
    if isinstance(t,str):
        for kw in ["deadline","Deadline","GRE","TOEFL","IELTS","Duolingo","tuition","Tuition","credit","month","part-time","full-time","STEM","fee","prerequisite","GPA","recommend"]:
            i=t.find(kw); print("  ",kw,"@",i)
        print(t[:2200])
