# -*- coding: utf-8 -*-
import io, sys, os, re, html as H
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
fn="_cornell_eas-meng_raw.html"
print("exists", os.path.exists(fn))
t=open(fn,encoding="utf-8").read()
body=re.sub(r"<script.*?</script>","",t,flags=re.S); body=re.sub(r"<style.*?</style>","",body,flags=re.S)
text=H.unescape(re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",body)))
open("_cornell_eas.txt","w",encoding="utf-8").write(text)
print("正文",len(text))
links=sorted(set(re.findall(r'href="(/eas/[^"]*)"',t)))
print("\nEAS 链接:")
for l in links: print("  ",l)
for kw in ["credit","semester","project","concentration","track","core","elective","30","Format","In-Person","Distance","prerequisite","geoscience","earth","5000"]:
    i=text.lower().find(kw.lower())
    if i>=0: print(f"\n[{kw}] ...{text[max(0,i-80):i+180]}...")
