# -*- 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"})
    try:
        with urllib.request.urlopen(req,context=ctx,timeout=15) as r:
            return r.status,r.read().decode("utf-8","ignore")
    except Exception as e:
        return "ERR",str(e)
def strip(t):
    t=re.sub(r"<script.*?</script>","",t,flags=re.S); t=re.sub(r"<style.*?</style>","",t,flags=re.S)
    t=re.sub(r"<[^>]+>"," ",t); return re.sub(r"\s+"," ",t).strip()
urls=[
 ("PRATT-REQ","https://masters.pratt.duke.edu/apply/requirements/"),
 ("PRATT-TUI","https://masters.pratt.duke.edu/admissions/tuition-financial-aid/"),
 ("PRATT-DEG","https://masters.pratt.duke.edu/programs/degree-requirements/"),
 ("GS-ENG","https://gradschool.duke.edu/academics/english-international-students/"),
 ("GS-ADM-STAT","https://gradschool.duke.edu/about/statistics/mechanical-engineering-and-materials-science-master-s-admissions-and-enrollment-statistics/"),
 ("GS-OUT","https://gradschool.duke.edu/about/statistics/mechanical-engineering-and-materials-science-master-s-career-outcomes-statistics/"),
]
for tag,u in urls:
    st,body=get(u)
    if st=="ERR":
        print("====",tag,"ERR",body[:90]); continue
    txt=strip(body)
    open("_duke_mems_"+tag.lower()+".html","w",encoding="utf-8").write(body)
    print("====",tag,"OK",st,"html",len(body),"txt",len(txt))
    print(txt[:2200]); print()
