# -*- 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
def get(u):
    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")
        h=re.sub(r"<script.*?</script>"," ",d,flags=re.S|re.I); h=re.sub(r"<style.*?</style>"," ",h,flags=re.S|re.I)
        t=re.sub(r"<[^>]+>"," ",h); t=re.sub(r"&nbsp;|&#x27;|&amp;|&#038;"," ",t); t=re.sub(r"\s+"," ",t)
        return t
    except Exception as e:
        return "ERR "+type(e).__name__+": "+str(e)[:120]

for u in ["https://masters.pratt.duke.edu/apply/requirements/",
          "https://masters.pratt.duke.edu/admissions/tuition-financial-aid/"]:
    t=get(u); print("="*30); print(u,"LEN",len(t))
    for kw in ["GRE","English","TOEFL","IELTS","Duolingo","Det","recommend","fee","tuition","credit","scholarship","MS Campus","Master of Science"]:
        for m in re.finditer(r".{12}"+re.escape(kw)+r".{90}",t):
            print(" ["+kw+"]",m.group(0).strip()[:180]); break
