# -*- coding: utf-8 -*-
import io, sys, os, re, urllib.request, ssl, html
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
cands={
 "cab39af":"https://e-catalogue.jhu.edu/public-health/departments/health-policy-management/health-finance-management-mhs/",
 "ca597d7":"https://e-catalogue.jhu.edu/public-health/departments/biochemistry-molecular-biology/biochemistry-molecular-biology-scm/",
 "cfe2f27":"https://e-catalogue.jhu.edu/medicine/graduate-programs/applied-health-sciences-informatics-ms/",
 "cd967c0":"https://e-catalogue.jhu.edu/engineering/full-time-residential-programs/degree-programs/applied-mathematics-statistics/data-science-masters-degree/",
 "c03ef7d":"https://e-catalogue.jhu.edu/arts-sciences/full-time-residential-programs/degree-programs/biophysics/biophysical-chemistry-design-biotechnology-master-science/",
 "cb6c788":"https://e-catalogue.jhu.edu/business/degrees-certificates/finance-master-science-financial-econometrics/",
 "c2babcf":"https://e-catalogue.jhu.edu/business/degrees-certificates/health-care-management-master-science/",
 "c064173":"https://e-catalogue.jhu.edu/engineering/full-time-residential-programs/degree-programs/biomedical-engineering/innovation-design-master-science-engineering/",
}
for t,u in cands.items():
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
        r=urllib.request.urlopen(req,timeout=12,context=ctx); b=r.read(); code=r.status
        raw=b.decode("utf-8","ignore"); raw=html.unescape(re.sub(r"<script.*?</script>","",raw,flags=re.S))
        txt=html.unescape(re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",raw)))
        flags=[w for w in ["online","part-time","Part-Time","Online","full-time","Full-Time","residential","STEM","thesis","Capstone"] if w in txt]
        print(f"{t} {code} {len(b)}B 形态={flags}")
        open(f"_22_{t}.txt","w",encoding="utf-8").write(txt)
    except Exception as e:
        print(f"{t} ERR {type(e).__name__} {e}")
