# -*- 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")
t=open("_cornell_aep-meng_raw.html",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_aep.txt","w",encoding="utf-8").write(text)
print("正文",len(text))
links=sorted(set(re.findall(r'href="(/aep/[^"]*)"',t)))
print("\nAEP 链接:")
for l in links: print("  ",l)
for kw in ["credit","semester","project","concentration","track","core","elective","30","Format","In-Person","Distance","prerequisite","physics","math"]:
    i=text.lower().find(kw.lower())
    if i>=0: print(f"\n[{kw}] ...{text[max(0,i-80):i+180]}...")
