# -*- coding: utf-8 -*-
import io, sys, os, re, ssl, urllib.request, html as h
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, timeout=25):
    req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
    try:
        r = urllib.request.urlopen(req, timeout=timeout, context=ctx)
        return r.status, r.read().decode("utf-8", errors="replace")
    except Exception as e:
        return None, f"ERR {type(e).__name__}"

for slug in ["master-real-estate-development", "architecture-ms"]:
    url = f"https://catalog.gatech.edu/programs/{slug}/"
    st, body = get(url)
    if st == 200:
        m = re.search(r'<title>([^<]+)</title>', body)
        title = m.group(1) if m else "?"
        courses = re.findall(r'<a[^>]+>([A-Z]{2,4}\s*\d{4}[^<]*)</a>', body)
        print(f"OK {len(body):>7}  {slug}")
        print(f"     title: {title[:100]}")
        print(f"     courses: {len(courses)}  sample: {courses[:8]}")
        # 提取 Degree / credits
        deg = re.search(r'Degree[:\s]*</[^>]+>\s*<[^>]+>([^<]+)', body)
        if deg: print("     degree:", deg.group(1).strip())
        open(f"_55_{slug}.html","w",encoding="utf-8").write(body)
    else:
        print(f"FAIL {body[:80]}  {slug}")
