# -*- coding: utf-8 -*-
import io, sys, os, ssl, re, html, urllib.request
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

# Try listing page
url="https://www.sgs.utoronto.ca/programs/"
req=urllib.request.Request(url,headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/120.0"})
r=urllib.request.urlopen(req,timeout=25,context=ctx)
b=r.read()
open("_36_list.html","wb").write(b)
raw=html.unescape(b.decode("utf-8",errors="replace"))
print("size",len(b))
# find all program links
links=re.findall(r'href="(/programs/[^"]+/)"',raw)
links=sorted(set(links))
print("total program links:",len(links))
# filter by keywords
for kw in ["electrical","computer-engineering","mechanical","industrial","health-informatics","materials","aerospace","chemical-engineering","physics","chemistry","biochemistry","management"]:
    hits=[l for l in links if kw in l]
    print(f"  {kw}: {hits}")
