# -*- coding: utf-8 -*-
import io,sys,ssl,urllib.request,re,html
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"})
        b=urllib.request.urlopen(req,timeout=20,context=ctx).read()
        return b.decode("utf-8","ignore"),len(b)
    except Exception as e:
        return "ERR "+repr(e),0
def clean(t):
    t=re.sub(r"<script.*?</script>"," ",t,flags=re.S); t=re.sub(r"<style.*?</style>"," ",t,flags=re.S)
    return html.unescape(re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",t)))
# 1 本页完整 requirement 正文
u="https://e-catalogue.jhu.edu/engineering/full-time-residential-programs/degree-programs/applied-mathematics-statistics/data-science-masters-degree/"
t,n=get(u)
i=t.find('id="requirementstextcontainer"')
seg=html.unescape(re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",re.sub(r"<script.*?</script>"," ",t[i:i+9000],flags=re.S))))
print("### REQ FULL\n",seg[:2200])
# 2 工程招生政策/学费通用页
for pu in [
 "https://e-catalogue.jhu.edu/engineering/engineering-graduate-policies/admissions-finances/",
 "https://e-catalogue.jhu.edu/university-wide-policies-information/admission-aid/tuition-fees/",
]:
    tt,nn=get(pu); print("\n### ",pu,nn)
    if not tt.startswith("ERR"):
        c=clean(tt)
        for kw in ["TOEFL","IELTS","Duolingo","GRE","deadline","August","January","December","tuition","Tuition","credit","application fee","transcript","recommend"]:
            j=c.find(kw)
            if j>=0: print(f"  [{kw}] ...{c[max(0,j-50):j+150]}...")
# 3 外部根域
for ru in ["https://engineering.jhu.edu/","https://engineering.jhu.edu/ams/"]:
    rr,rn=get(ru); print("\nROOT",ru,rn,rr[:60])
