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

slugs = [
    "computational-science-engineering-ms",
    "economics-ms",
    "urban-analytics-ms",
    "mechanical-engineering-ms",
    "bioinformatics-ms",
]
for s in slugs:
    txt = open(f"_47_{s}.html", encoding="utf-8").read()
    # Total Credit Hours
    m = re.search(r'Total Credit Hours[^<]*</td>\s*<td[^>]*>(\d+)', txt)
    total = m.group(1) if m else "?"
    # 课程表：提取 areaheader + comment 行
    rows = re.findall(r'<span class="courselistcomment[^"]*">([^<]+)</span>(?:</td><td[^>]*></td><td[^>]*>(\d+))?', txt)
    print(f"\n=== {s}  total={total}cr ===")
    for comment, hrs in rows[:25]:
        c = htmlmod.unescape(comment).strip()
        if hrs:
            print(f"   [{hrs}cr] {c}")
        else:
            print(f"   {c}")
