# -*- 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")

targets=[
 ("ut-cheme-masc","chemical-engineering"),
 ("ut-math-msc","mathematics"),
 ("ut-biochem-msc","biochemistry"),
 ("ut-mgmt-mmgt","master-of-management"),
 ("ut-hpme-msc","health-policy-management-and-evaluation"),
]
for tid,slug in targets:
    raw=open(f"_38_{slug}.html",encoding="utf-8").read()
    i=raw.lower().find("quick facts")
    seg=raw[i:i+15000]
    # cut at next </table>
    j=seg.lower().find("</table>")
    seg=seg[:j+8] if j>0 else seg
    rows=re.findall(r"<tr[^>]*>(.*?)</tr>", seg, re.S|re.I)
    print("="*70)
    print(tid, slug)
    for r in rows:
        cells=re.findall(r"<td[^>]*>(.*?)</td>", r, re.S|re.I)
        if len(cells)>=2:
            label=re.sub(r"<[^>]+>"," ",cells[0]); label=html.unescape(label).strip()
            val=re.sub(r"<[^>]+>"," ",cells[1]); val=html.unescape(val).strip()
            val=re.sub(r"\s+"," ",val)
            label=re.sub(r"\s+"," ",label)
            if label:
                print(f"  [{label}] => {val[:300]}")
