# -*- 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))

files=[
 ("cornell-c89ab8d.html","Mechanical Engineering MS"),
 ("cornell-c524860.html","Chemical Engineering MS"),
 ("cornell-cbd0bbe.html","Civil and Environmental Engineering MS"),
 ("cornell-c5d718f.html","Materials Science and Engineering MS"),
 ("cornell-c396d2c.html","Applied Physics MS"),
]
for base,label in files:
    t=load("_34_"+base)
    print("====",label,"====")
    # 找 MS / Master of Science 相关正文
    for kw in ["Master of Science","M.S.","MS in","graduate degree","thesis","coursework","admission","deadline","GRE","TOEFL","IELTS","tuition","part-time","online","full-time","residential","on-campus","on campus"]:
        i=t.lower().find(kw.lower())
        if i>0:
            seg=t[max(0,i-80):i+260]
            print(f"[{kw}] ...{seg}...")
            break
    # 再找第二个关键段
    for kw in ["thesis","coursework","30 credit","30 credits","credits","required","duration","1 year","two years","2 year"]:
        i=t.lower().find(kw.lower())
        if i>0:
            print(f"  [{kw}] ...{t[max(0,i-60):i+220]}...")
            break
    print()
