# -*- 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)

# UNC MHA 深挖学分和课程
url = "https://catalog.unc.edu/graduate/schools-departments/health-policy-management/"
st, body = get(url)
print(f"=== UNC MHA: {st} {len(body)} ===")
# 找 MHA Degree Requirements 段
idx = body.find("MHA Degree Requirements")
if idx < 0: idx = body.find("Master of Health Administration")
if idx > 0:
    txt = re.sub(r'<[^>]+>', ' ', body[idx:idx+3000])
    txt = h.unescape(re.sub(r'\s+', ' ', txt))
    print(txt[:1000])

# UNC MAPS 深挖学分
url2 = "https://catalog.unc.edu/graduate/schools-departments/applied-professional-studies/"
st2, body2 = get(url2)
print(f"\n=== UNC MAPS: {st2} {len(body2)} ===")
idx2 = body2.find("Degree Requirements")
if idx2 < 0: idx2 = body2.find("Requirements")
if idx2 > 0:
    txt2 = re.sub(r'<[^>]+>', ' ', body2[idx2:idx2+2000])
    txt2 = h.unescape(re.sub(r'\s+', ' ', txt2))
    print(txt2[:800])

# UNC Global Studies MA 深挖
url3 = "https://catalog.unc.edu/graduate/schools-departments/global-studies/"
st3, body3 = get(url3)
print(f"\n=== UNC Global Studies MA: {st3} {len(body3)} ===")
idx3 = body3.find("Degree Requirements")
if idx3 < 0: idx3 = body3.find("Master's (Non-Thesis)")
if idx3 > 0:
    txt3 = re.sub(r'<[^>]+>', ' ', body3[idx3:idx3+2000])
    txt3 = h.unescape(re.sub(r'\s+', ' ', txt3))
    print(txt3[:800])

# UNC MA in Media and Communication 深挖
url4 = "https://catalog.unc.edu/graduate/schools-departments/media-journalism/"
st4, body4 = get(url4)
print(f"\n=== UNC MA Media and Comm: {st4} {len(body4)} ===")
idx4 = body4.find("Degree Requirements")
if idx4 < 0: idx4 = body4.find("Master of arts in media and communication")
if idx4 > 0:
    txt4 = re.sub(r'<[^>]+>', ' ', body4[idx4:idx4+2000])
    txt4 = h.unescape(re.sub(r'\s+', ' ', txt4))
    print(txt4[:800])
