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

ctx = ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
def get(url, t=25):
    req=urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
    try:
        r=urllib.request.urlopen(req, timeout=t, context=ctx)
        b=r.read(); return r.status, b
    except Exception as e:
        return None, str(e).encode("utf-8","ignore")

slugs = [
    "biomedical-engineering-ms",
    "chemical-engineering-ms",
    "civil-engineering-ms",
    "mathematics-ms",
    "robotics-ms",
]
for s in slugs:
    u = f"https://catalog.gatech.edu/programs/{s}/"
    st, body = get(u)
    if st != 200:
        print("FAIL", st, s, body[:150]); continue
    txt = body.decode("utf-8","ignore")
    open(f"_48_{s}.html","w",encoding="utf-8").write(txt)
    m = re.search(r'Total Credit Hours[^<]*</td>\s*<td[^>]*>(\d+)', txt)
    total = m.group(1) if m else "?"
    rows = re.findall(r'<span class="courselistcomment[^"]*">([^<]+)</span>(?:</td><td[^>]*></td><td[^>]*>(\d+))?', txt)
    print(f"\n=== {s}  size={len(body)}  total={total}cr ===")
    for comment, hrs in rows[:20]:
        c = htmlmod.unescape(comment).strip()
        if hrs:
            print(f"   [{hrs}cr] {c}")
        else:
            print(f"   {c}")
