import ssl, urllib.request, re, sys, io
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 fetch(u):
    req=urllib.request.Request(u, headers={"User-Agent":"Mozilla/5.0"})
    return urllib.request.urlopen(req, context=ctx, timeout=25).read().decode("utf-8","ignore")
def text(h):
    h=re.sub(r'<script.*?</script>',' ',h,flags=re.S|re.I); h=re.sub(r'<style.*?</style>',' ',h,flags=re.S|re.I)
    h=re.sub(r'<[^>]+>',' ',h)
    for a,b in [('&nbsp;',' '),('&amp;','&'),('&#39;',"'"),('&#8217;',"'"),('&#x27;',"'")]: h=h.replace(a,b)
    h=re.sub(r'\s+',' ',h); return h.strip()

for u in ["https://advancedscholars.uchicago.edu/how-to-apply/",
          "https://economics.uchicago.edu/mae"]:
    try:
        h=fetch(u); t=text(h)
        print("="*25,u,"textlen=",len(t))
        print(t[:2600]); print()
    except Exception as e:
        print("ERR",u,type(e).__name__,str(e)[:120])
