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

# Cornell Chemistry - 找 M.S. Program 正文
t=load("_35_cornell-c239b95.html")
print("=== Cornell Chemistry MS 正文 ===")
for kw in ["one-year","M.S. Program","master's","terminal","coursework","thesis","admission","apply","deadline"]:
    i=t.lower().find(kw.lower())
    if i>0: print(f"[{kw}] ...{t[max(0,i-80):i+300]}...\n")

# Dartmouth Chemistry - 找 4+1
t=load("_35_dartmouth-chemistry-ms.html")
print("=== Dartmouth Chemistry 4+1 正文 ===")
for kw in ["4+1","Master's Program","master","current Dartmouth","Dartmouth undergrad","fifth year","combined"]:
    i=t.lower().find(kw.lower())
    if i>0: print(f"[{kw}] ...{t[max(0,i-80):i+300]}...\n")

# Dartmouth Math - 找 MA
t=load("_35_dartmouth-mathematics-ma.html")
print("=== Dartmouth Math MA 正文 ===")
for kw in ["M.A.","master","PhD","terminal","coursework","thesis","admission","degree"]:
    i=t.lower().find(kw.lower())
    if i>0: print(f"[{kw}] ...{t[max(0,i-60):i+260]}...\n")

# Cornell BEE - 找 graduate/MS
t=load("_35_cornell-c47af79.html")
print("=== Cornell BEE graduate 正文 ===")
for kw in ["M.Eng.","M.S.","Ph.D.","graduate degree","thesis","admission","master","terminal"]:
    i=t.lower().find(kw.lower())
    if i>0: print(f"[{kw}] ...{t[max(0,i-60):i+260]}...\n")
