# -*- coding: utf-8 -*-
import io, sys, os, ssl, urllib.request, re, html as htmllib
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

# 1. NYU Biostatistics 详细提取
print("===== NYU Biostatistics MS 详细 =====")
txt=open("_43_nyu_biostat.html",encoding="utf-8",errors="ignore").read()
# 提取课程表/学分
credits=re.findall(r'GPH-GU\s*\d+[^<]*', txt)
print("课程样例:", credits[:10])
# 找总学分
m=re.search(r'(\d+)\s*[Cc]redits?', txt)
if m: print("总学分:", m.group(0))
# 找 admission 要求段
m=re.search(r'Admissions.*?(?=<h[12]|Program Requirements|Tuition)', txt, re.S|re.I)
if m:
    t=re.sub(r'<[^>]+>',' ',m.group(0))
    t=htmllib.unescape(re.sub(r'\s+',' ',t)).strip()
    print("Admissions 段:", t[:600])

# 2. Cornell BEE 详细
print("\n===== Cornell BEE graduate-programs 详细 =====")
txt=open("_43_cornell_bee.html",encoding="utf-8",errors="ignore").read()
# 找 MS / MEng / PhD 相关
for kw in ["M.Eng","M.S.","PhD","Master of Engineering","Master of Science","degree","admission","application","deadline","TOEFL","GRE","Tuition","credits","thesis"]:
    m=re.search(r'.{0,80}'+re.escape(kw)+r'.{0,250}', txt, re.S|re.I)
    if m:
        t=re.sub(r'<[^>]+>',' ',m.group(0))
        t=htmllib.unescape(re.sub(r'\s+',' ',t)).strip()
        print(f"  [{kw}] {t[:280]}")

# 3. JHU e-catalogue AAP 路径探测
print("\n===== JHU e-catalogue AAP 路径 =====")
for path in [
    "https://e-catalogue.jhu.edu/advanced-academic-programs/graduate/applied-economics-ms/",
    "https://e-catalogue.jhu.edu/engineering/graduate/applied-economics-ms/",
    "https://e-catalogue.jhu.edu/advanced-academic-programs/",
]:
    try:
        req=urllib.request.Request(path,headers={"User-Agent":"Mozilla/5.0"})
        r=urllib.request.urlopen(req,timeout=12,context=ctx)
        b=r.read()
        print(path,"->",r.status,len(b))
        if r.status==200 and "advanced-academic" in path:
            open("_43_jhu_aap.html","wb").write(b)
    except Exception as e:
        print(path,"->",type(e).__name__,str(e)[:60])
