import re, os

base = os.path.dirname(os.path.abspath(__file__))
html = open(os.path.join(base, "index_main.html"), encoding="utf-8").read()

ids = ["berkeley-biostat-ma", "brown-scm-biostat", "umich-me-mse", "ucsd-mae-ms",
       "umich-robotics-ms", "usc-apmath-ms", "umich-bme-ms", "cornell-mps-aem"]
det = [f"details/{i}.html" for i in ids]

catd_block = re.search(r'const CATD=\[(.*?)\];', html, re.S).group(1)
rows = re.findall(r'\[(.*?)\]', catd_block)
for d in det:
    hits = [r for r in rows if d in r]
    for h in hits:
        fields = re.findall(r'"([^"]*)"', h)
        # 8 元素: school,college,en,n,deg,url_official,disc,det
        n = fields[3] if len(fields) > 3 else "?"
        en = fields[2] if len(fields) > 2 else "?"
        print(f"{d} | CATD n={n} | en={en}")
    if not hits:
        print(f"{d} | CATD 无对应行")
