# -*- 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
urls=[
 "https://gradschool.duke.edu/academics/programs-degrees/quantitative-financial-economics/",
 "https://econ.duke.edu/graduate/masters-programs/quantitative-financial-economics",
 "https://www.fuqua.duke.edu/programs/duke-ms-finance",
]
def clean(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)
    h=re.sub(r"&nbsp;"," ",h); h=re.sub(r"&amp;","&",h)
    h=re.sub(r"\s+"," ",h)
    return h.strip()
for u in urls:
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
        d=urllib.request.urlopen(req,context=ctx,timeout=20).read().decode("utf-8","ignore")
        t=clean(d)
        print("====",u,"len=",len(d),"textlen=",len(t))
        print(t[:1800])
        print()
    except Exception as e:
        print("====",u,"ERR",repr(e))
