# -*- coding: utf-8 -*-
import ssl,urllib.request,re,io,sys
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,context=ctx,timeout=20) as r:
        b=r.read(); return r.status,len(b),b.decode("utf-8","ignore")
for name,u in [("dead","https://masters.pratt.duke.edu/apply/deadlines/")]:
    try:
        st,ln,t=get(u); open("_duke_cee_"+name+".html","w",encoding="utf-8").write(t)
        txt=re.sub(r"<script.*?</script>","",t,flags=re.S); txt=re.sub(r"<style.*?</style>","",txt,flags=re.S)
        txt=re.sub(r"<[^>]+>"," ",txt); txt=re.sub(r"\s+"," ",txt).strip()
        print("====",name,st,"HTML",ln,"TXT",len(txt))
        print(txt[:4000])
    except Exception as e:
        print("====",name,"ERR",repr(e))
