# -*- 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
UA = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36"}

def get(url, timeout=20):
    try:
        req = urllib.request.Request(url, headers=UA)
        r = urllib.request.urlopen(req, timeout=timeout, context=ctx)
        return r.status, r.read().decode("utf-8", errors="ignore")
    except Exception as e:
        return -1, str(e)

# GaTech international-affairs-science-technology-ms
url = "https://catalog.gatech.edu/programs/international-affairs-science-technology-ms/"
st, body = get(url)
print(f"=== GaTech IAST MS: {st} {len(body)} ===")
if st == 200:
    idx = body.find("Program of Study")
    if idx < 0: idx = body.find("Overview")
    if idx > 0:
        txt = re.sub(r'<[^>]+>', ' ', body[idx:idx+1200])
        txt = h.unescape(re.sub(r'\s+', ' ', txt))
        print(txt[:500])
    credits = re.findall(r'(\d+)\s*credit', body, re.I)
    print("credits:", credits[:5])

# UNC MHA 深挖学分和方向
url2 = "https://catalog.unc.edu/graduate/schools-departments/health-policy-management/"
st2, body2 = get(url2)
print(f"\n=== UNC MHA: {st2} {len(body2)} ===")
# 找 MHA 详细段
idx2 = body2.find("Master of Health Administration (MHA)")
if idx2 > 0:
    txt2 = re.sub(r'<[^>]+>', ' ', body2[idx2:idx2+2500])
    txt2 = h.unescape(re.sub(r'\s+', ' ', txt2))
    print(txt2[:800])

# UNC MAPS 深挖
url3 = "https://catalog.unc.edu/graduate/schools-departments/applied-professional-studies/"
st3, body3 = get(url3)
print(f"\n=== UNC MAPS: {st3} {len(body3)} ===")
idx3 = body3.find("master of applied professional studies")
if idx3 > 0:
    txt3 = re.sub(r'<[^>]+>', ' ', body3[idx3:idx3+2000])
    txt3 = h.unescape(re.sub(r'\s+', ' ', txt3))
    print(txt3[:700])

# UNC Global Studies MA 深挖
url4 = "https://catalog.unc.edu/graduate/schools-departments/global-studies/"
st4, body4 = get(url4)
print(f"\n=== UNC Global Studies MA: {st4} {len(body4)} ===")
idx4 = body4.find("Master's (Non-Thesis)")
if idx4 > 0:
    txt4 = re.sub(r'<[^>]+>', ' ', body4[idx4:idx4+1500])
    txt4 = h.unescape(re.sub(r'\s+', ' ', txt4))
    print(txt4[:600])

# UNC MA in Media and Communication 深挖
url5 = "https://catalog.unc.edu/graduate/schools-departments/media-journalism/"
st5, body5 = get(url5)
print(f"\n=== UNC MA Media and Comm: {st5} {len(body5)} ===")
idx5 = body5.find("Master of arts in media and communication")
if idx5 > 0:
    txt5 = re.sub(r'<[^>]+>', ' ', body5[idx5:idx5+1500])
    txt5 = h.unescape(re.sub(r'\s+', ' ', txt5))
    print(txt5[:600])
