# -*- 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"})
    return urllib.request.urlopen(req,context=ctx,timeout=25).read().decode("utf-8","ignore")
def strip(h):
    h=re.sub(r"<script[\s\S]*?</script>","",h); h=re.sub(r"<style[\s\S]*?</style>","",h)
    h=re.sub(r"<[^>]+>"," ",h); h=re.sub(r"[ \t]+"," ",h)
    h=re.sub(r"\n\s*\n+","\n",h); return h.strip()

# requirements 页：按锚点切块
t=strip(get("https://masters.pratt.duke.edu/apply/requirements/"))
for kw in ["English Language","GRE","Application Fee","Minimum Application","Recommendations","Resume","Transcript"]:
    i=t.lower().find(kw.lower())
    if i>=0: print("###",kw,"\n",t[i:i+700],"\n")

print("="*20,"TUITION")
tt=strip(get("https://masters.pratt.duke.edu/admissions/tuition-financial-aid/"))
print(tt[:2500])
print("="*20,"DEGREE REQ")
td=strip(get("https://masters.pratt.duke.edu/programs/degree-requirements/"))
print(td[:2500])
