# -*- coding: utf-8 -*-
import io, sys, os, re, html
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")

def load(f):
    b=open(f,"rb").read()
    t=html.unescape(re.sub(r"<script[\s\S]*?</script>|<style[\s\S]*?</style>"," ",b.decode("utf-8","ignore")))
    return re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",t))

# 对每条，找 "Master of Science" 正文段（跳过导航菜单）
files=[
 ("cornell-c89ab8d.html","ME"),
 ("cornell-c524860.html","ChE"),
 ("cornell-cbd0bbe.html","CEE"),
 ("cornell-c5d718f.html","MSE"),
 ("cornell-c396d2c.html","AppPhys"),
]
for base,tag in files:
    t=load("_34_"+base)
    print("====",tag,"====")
    # 找所有 "Master of Science" 出现位置
    idxs=[m.start() for m in re.finditer(r"Master of Science",t)]
    # 取第三个以后（跳过导航）
    for i in idxs[2:4]:
        print(t[i:i+500])
        print("---")
    # 找方向/学分/学制
    for kw in ["Concentration","credit","year","duration","financial support","assistantship","fellowship","deadline","December","January","February","GRE","TOEFL","IELTS","English"]:
        i=t.lower().find(kw.lower())
        if i>0:
            print(f"  [{kw}] {t[max(0,i-40):i+200]}")
    print()
