# -*- 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"})
    r = urllib.request.urlopen(req, timeout=timeout, context=ctx)
    return r.read().decode("utf-8", errors="replace")

body = get("https://catalog.gatech.edu/programs/urban-design-msud/")
# 找 article 或 main-content 段
# 先看 body 里所有 h1/h2/h3
for m in re.finditer(r'<h[1-3][^>]*>([\s\S]{0,200}?)</h[1-3]>', body):
    txt = re.sub(r'<[^>]+>', ' ', m.group(1))
    txt = h.unescape(re.sub(r'\s+',' ',txt)).strip()
    if txt and len(txt) < 120:
        print("H:", txt)
print("---")
# 找 Program of Study 段
pos = body.find("Program of Study")
if pos > 0:
    seg = body[pos:pos+5000]
    seg = re.sub(r'<[^>]+>', ' ', seg)
    seg = h.unescape(re.sub(r'\s+',' ',seg)).strip()
    print("POS:", seg[:2000])
