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

# GaTech catalog 索引：找硕士项目列表
urls = [
    "https://catalog.gatech.edu/programs/",
    "https://catalog.gatech.edu/programs/?acad_level=graduate",
]
for u in urls:
    st, body = get(u)
    if st != 200:
        print("FAIL", st, u, body[:200])
        continue
    txt = body.decode("utf-8", "ignore")
    print("OK", st, len(body), u)
    # 抓 /programs/<slug>/ 链接
    slugs = re.findall(r'href="(/programs/([a-z0-9\-]+)/?)"', txt)
    seen=set(); uniq=[]
    for full, slug in slugs:
        if slug in seen: continue
        seen.add(slug); uniq.append(slug)
    print("  slugs:", len(uniq))
    for s in uniq[:80]:
        print("   ", s)
    open("_47_index.html","w",encoding="utf-8").write(txt)
    break
