# -*- 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/admissions/application-instructions/"
t=get(u)
open("_duke_mse_gs-inst.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))
for kw in ["application fee","Application Fee","$75","TOEFL","IELTS","Duolingo","recommendation","Recommendation","GPA","GRE","English","waiver","transcript","statement of purpose","résumé","resume"]:
    i=txt.find(kw)
    if i>=0:
        print("###",kw); print(txt[max(0,i-140):i+300]); print("-"*60)
