# -*- coding: utf-8 -*-
import urllib.request, ssl, gzip, io, sys, re, os
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
hdr={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/120 Safari/537.36","Accept-Language":"en-US,en;q=0.9"}
def fetch(u, t=20):
    try:
        r=urllib.request.urlopen(urllib.request.Request(u,headers=hdr),timeout=t,context=ctx)
        b=r.read()
        if r.headers.get("Content-Encoding")=="gzip": b=gzip.decompress(b)
        return r.status, len(b), b.decode("utf-8","ignore")
    except Exception as e:
        return -1, 0, str(e)

base="https://e-catalogue.jhu.edu"
paths=[
    "/arts-sciences/advanced-academic-programs/programs/applied-economics-master-science/",
    "/arts-sciences/advanced-academic-programs/programs/center-biotechnology-education/bioinformatics-master-science/",
    "/arts-sciences/advanced-academic-programs/programs/cultural-heritage-management-master-arts/",
    "/arts-sciences/advanced-academic-programs/programs/financial-economics-master-science/",
    "/arts-sciences/advanced-academic-programs/programs/geographic-information-systems-master-science/",
]
for p in paths:
    u=base+p
    s,n,h = fetch(u)
    print("===",s,n,p)
    if s!=200: continue
    # 去标签取正文
    txt=re.sub(r"<script[\s\S]*?</script>"," ",h,flags=re.I)
    txt=re.sub(r"<style[\s\S]*?</style>"," ",txt,flags=re.I)
    txt=re.sub(r"<[^>]+>"," ",txt)
    txt=re.sub(r"\s+"," ",txt)
    # 关键词
    for kw in ["on-campus","online","part-time","full-time","at a distance","evening","weekend","working professionals","stem","STEM","credits","Admission Requirements","Tuition","deadline","TOEFL","IELTS","GRE"]:
        m=re.search(r".{0,80}"+re.escape(kw)+r".{0,120}", txt, re.I)
        if m: print("  ",kw,"→",m.group(0).strip()[:200])
    print()
