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

files = {
    "intl-sec": "_55_international-security-ms.html",
    "mbid": "_55_master-biomedical-innovation-development.html",
    "pmase": "_55_applied-systems-engineering-pmase.html",
    "mred": "_55_master-real-estate-development.html",
    "arch-ms": "_55_architecture-ms.html",
}
for tag, fn in files.items():
    body = open(fn, encoding="utf-8").read()
    # 提取课程行（Course Code Title Credit Hours）
    # 匹配 table 行
    rows = re.findall(r'<tr[^>]*>(.*?)</tr>', body, re.S)
    courses = []
    for row in rows:
        cells = re.findall(r'<t[dh][^>]*>(.*?)</t[dh]>', row, re.S)
        cells = [h.unescape(re.sub(r'<[^>]+>','',c)).strip() for c in cells]
        if len(cells) >= 2 and re.match(r'^[A-Z]{2,4}\s*\d{3,4}', cells[0]):
            courses.append(cells)
    print(f"\n===== {tag} ({fn}) =====")
    for c in courses[:25]:
        print("  ", " | ".join(c[:4]))
