# -*- 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:
        return r.read().decode("utf-8","ignore")
u="https://gradschool.duke.edu/academics/programs-degrees/mechanical-engineering-and-materials-science-ms/"
t=get(u)
open("_duke_mems_page.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("HTML_LEN",len(t),"TXT_LEN",len(txt))
print(txt[:6000])
