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

def text_of(p):
    t = p.read_text(encoding="utf-8", errors="ignore")
    t = re.sub(r"<script.*?</script>", " ", t, flags=re.S|re.I)
    t = re.sub(r"<style.*?</style>", " ", t, flags=re.S|re.I)
    t = re.sub(r"<br\s*/?>", "\n", t, flags=re.I)
    t = re.sub(r"</(p|div|li|tr|h\d)>", "\n", t, flags=re.I)
    t = re.sub(r"<[^>]+>", " ", t)
    t = H.unescape(t)
    t = re.sub(r"[ \t\r\f\v]+", " ", t)
    t = re.sub(r"\n\s*\n+", "\n", t)
    return t.strip()

k = "gatech-cs"
t = text_of(CACHE / (k + ".html"))
# find main content anchor
for anchor in ["Master of Science in Computer Science", "Program of Study", "Degree Requirements", "For more information"]:
    idx = t.rfind(anchor)
    print("anchor", anchor, idx)
i = t.rfind("Master of Science in Computer Science")
print("-" * 40)
print(t[i:i+6000])
