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

SCTX = ssl.create_default_context()
SCTX.check_hostname = False
SCTX.verify_mode = ssl.CERT_NONE

for slug in ["education", "nursing", "music-performance", "global-professional-law"]:
    url = f"https://www.sgs.utoronto.ca/programs/{slug}/"
    req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
    html = urllib.request.urlopen(req, timeout=15, context=SCTX).read().decode("utf-8", errors="ignore")
    # 找所有 td 内容
    tds = re.findall(r'<td[^>]*>(.*?)</td>', html, re.S)
    tds = [re.sub(r'<[^>]+>', '', t).strip() for t in tds]
    tds = [t for t in tds if t]
    print(f"\n=== {slug} (td数: {len(tds)}) ===")
    for i, t in enumerate(tds[:30]):
        print(f"  [{i}] {t[:100]}")
    # 找 h1/h2/h3
    heads = re.findall(r'<h[123][^>]*>(.*?)</h[123]>', html, re.S)
    heads = [re.sub(r'<[^>]+>', '', h).strip() for h in heads]
    heads = [h for h in heads if h]
    print("  Headers:", heads[:10])
