# -*- coding: utf-8 -*-
import io, sys, os, ssl, urllib.request, html as htmllib, re
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
s="nutritional-sciences"
url=f"https://www.sgs.utoronto.ca/programs/{s}/"
req=urllib.request.Request(url,headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0"})
r=urllib.request.urlopen(req,timeout=20,context=ctx)
b=r.read()
open(f"_42_{s}.html","wb").write(b)
txt=b.decode("utf-8",errors="ignore")
m=re.search(r'Quick Facts(.{200,8000}?)(?:</table>|</section>|Research Highlights|Admission Requirements|Faculty)', txt, re.S|re.I)
if m:
    seg=m.group(1)
    rows=re.findall(r'<tr[^>]*>(.*?)</tr>', seg, re.S|re.I)
    print(f"===== {s} ({len(b)}B) =====")
    for row in rows[:30]:
        tds=re.findall(r'<td[^>]*>(.*?)</td>', row, re.S|re.I)
        tds=[re.sub(r'<[^>]+>','',x).strip() for x in tds]
        tds=[htmllib.unescape(x) for x in tds if x.strip()]
        if tds: print(" | ".join(tds))
