# -*- 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_sys-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_sys.txt","w",encoding="utf-8").write(text)
print("正文长度:",len(text))
# 链接矩阵
links=sorted(set(re.findall(r'href="([^"]*sys[^"]*)"',t)))
print("\nSYS 相关链接:")
for l in links: print("  ",l)
# 关键词切片
for kw in ["credit","semester","project","concentration","deadline","GRE","TOEFL","IELTS","tuition","fee","STEM","OPT","admission","prerequisite","GPA","recommendation","statement","resume","résumé"]:
    i=text.lower().find(kw.lower())
    if i>=0:
        print(f"\n[{kw}] ...{text[max(0,i-90):i+170]}...")
