# -*- 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__}"

# 真正的新候选（与已录 id 不同的 slug）
cands = [
    "computational-science-engineering-ms",
    "international-security-ms",
    "master-biomedical-innovation-development",
    "applied-systems-engineering-pmase",
    "mechanical-engineering-undesignated-ms",
]
for slug in cands:
    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 "?"
        # 提取 Degree 行
        deg = re.search(r'Degree[:\s]*</[^>]+>\s*<[^>]+>([^<]+)', body)
        # 提取 Program of Study 课程数
        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[:5]}")
        # 保存
        open(f"_55_{slug}.html","w",encoding="utf-8").write(body)
    else:
        print(f"FAIL {body[:50]}  {slug}")
