# -*- 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=20):
    req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
    try:
        r = urllib.request.urlopen(req, timeout=timeout, context=ctx)
        b = r.read()
        return r.status, len(b), b.decode("utf-8", errors="replace")
    except Exception as e:
        return None, 0, f"ERR {type(e).__name__}: {e}"

slugs = [
    "international-affairs-science-technology-ms",
    "master-sustainable-energy-environmental-management",
    "urban-design-msud",
    "bioengineering-ms",
    "engineering-science-mechanics-ms",
]
for s in slugs:
    url = f"https://catalog.gatech.edu/programs/{s}/"
    st, n, body = get(url)
    print(f"\n== {s} == {st} {n}")
    if st == 200 and n > 5000:
        # 提取项目标题、学位、学分、方向
        title = re.search(r"<title>([^<]+)</title>", body, re.I)
        print("  title:", h.unescape(title.group(1).strip())[:120] if title else "?")
        # 找 degree
        deg = re.search(r'(Degree|degree)[^<]*<[^>]*>([^<]+)', body)
        # 找 credit hours
        cr = re.findall(r'(\d+)\s*[Cc]redit', body)
        print("  credits mentioned:", cr[:8])
        # 找 overview
        ov = re.search(r'(Overview|Program of Study|Degree Requirements)[\s\S]{0,2000}', body)
        if ov:
            txt = re.sub(r'<[^>]+>', ' ', ov.group(0))
            txt = h.unescape(re.sub(r'\s+', ' ', txt)).strip()
            print("  overview:", txt[:500])
