# -*- 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()

req=get("https://masters.pratt.duke.edu/apply/requirements/")
for aid in ["english-test","gre-scores","application-fee","minimum","recommendations"]:
    m=re.search(r'id="%s"[\s\S]{0,1600}'%aid,req)
    if m: print("###",aid,"\n",strip(m.group(0))[:900],"\n")

print("="*20,"DEGREE REQ MS 段")
dr=get("https://masters.pratt.duke.edu/programs/degree-requirements/")
t=strip(dr)
i=t.find("Master of Science")
# 找第二个出现（正文，非导航）
j=t.find("Master of Science", i+20)
print(t[j:j+1800] if j>0 else t[i:i+1800])
