# -*- 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 = [
    "computational-science-engineering-ms",
    "economics-ms",
    "urban-analytics-ms",
    "mechanical-engineering-ms",
    "bioinformatics-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"_47_{s}.html","w",encoding="utf-8").write(txt)
    # 提取学位要求段
    # 找 Degree Name / 学位、学分、Program of Study
    deg = re.search(r'Degree Name[^<]*<[^>]*>\s*([^<]+?)\s*<', txt)
    # 学分
    cred = re.findall(r'(\d+)\s*Credit Hours', txt)
    # 找 "Program of Study" 段
    pos = txt.find("Program of Study")
    snippet = txt[pos:pos+3000] if pos>0 else ""
    # 去标签
    snippet_txt = re.sub(r'<[^>]+>',' ', snippet)
    snippet_txt = htmlmod.unescape(snippet_txt)
    snippet_txt = re.sub(r'\s+',' ', snippet_txt).strip()
    print(f"\n=== {s}  size={len(body)} ===")
    print("  deg:", deg.group(1) if deg else "?")
    print("  credit tokens:", cred[:10])
    print("  POS snippet:", snippet_txt[:600])
