# -*- coding: utf-8 -*-
import sys, io, re
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
BASE = r"D:\work buddy\2026-11-05-14-15-52"

def txt(p):
    h = open(p, encoding="utf-8", errors="replace").read()
    h = re.sub(r"<script.*?</script>", " ", h, flags=re.S)
    h = re.sub(r"<style.*?</style>", " ", h, flags=re.S)
    h = re.sub(r"<[^>]+>", "\n", h)
    h = re.sub(r"&nbsp;", " ", h)
    h = re.sub(r"&amp;", "&", h)
    h = re.sub(r"\n\s*\n+", "\n", h)
    return h

for k in ["wlu-cs-mmath-p", "wlu-stat-mmath-p", "wlu-biostat-mmath-p", "wlu-mdsai-p", "wlu-ds-mmath-p"]:
    t = txt(BASE + "\\cache\\r348-" + k + ".html")
    open(BASE + "\\_r348-new-" + k + ".txt", "w", encoding="utf-8").write(t)
    codes = sorted(set(re.findall(r"\b(?:CS|STAT|ACTSC|MATH|CO|ECE|MSCI|ECON|AMATH|COMM|DATSC)\s?\d{3}\b", t)))
    print("\n=====", k, "chars", len(t), "codes", len(codes))
    print(codes[:30])
    # 关键段落
    for kw in ["Admission", "Tuition", "tuition", "Deadline", "deadline", "Application", "Fees", "fees", "Duration"]:
        i = t.find(kw)
        if i > 0:
            print("  --", kw, ":", re.sub(r"\s+", " ", t[i:i+260]))
