# -*- 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")
for tag in ["MChE","MCEE","MMSNE","MBE"]:
    h=open(f"_rice12_{tag}.html",encoding="utf-8",errors="ignore").read()
    h=re.sub(r"<script.*?</script>","",h,flags=re.S)
    h=re.sub(r"<style.*?</style>","",h,flags=re.S)
    t=re.sub(r"<[^>]+>"," ",h); t=html.unescape(re.sub(r"\s+"," ",t))
    open(f"_rice12_{tag}.txt","w",encoding="utf-8").write(t)
    print("="*14,tag,len(t))
    for kw in ["Master of Chemical","Master of Civil","Master of Materials","Master of Bioengineering","credit hours","non-thesis","final project","specialization","STEM","full-time","part-time","track","concentration"]:
        m=re.search(re.escape(kw),t,re.I)
        if m:
            seg=t[max(0,m.start()-40):m.start()+150]
            print(f"  [{kw}] {seg}")
