# -*- coding: utf-8 -*-
import io, sys, os, re, ssl, urllib.request
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=20):
    req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
    try:
        r = urllib.request.urlopen(req, timeout=timeout, context=ctx)
        b = r.read()
        return r.status, len(b), b.decode("utf-8", errors="replace")
    except Exception as e:
        return None, 0, f"ERR {e}"

candidates = [
    # UVA Data Science MS
    ("UVA DS", "https://dsi.virginia.edu/academics/ms-data-science"),
    ("UVA DS2", "https://dsi.virginia.edu/academics/msds"),
    ("UVA DS3", "https://data.virginia.edu/academics/ms-data-science/"),
    # UVA Accounting MS (McIntire)
    ("UVA MSA", "https://comm.virginia.edu/graduate/ms-accounting"),
    ("UVA MSA2", "https://comm.virginia.edu/graduate/ms-in-accounting"),
    # UVA MIT (McIntire)
    ("UVA MIT", "https://comm.virginia.edu/graduate/mit"),
    # UNC Applied Data Science MA
    ("UNC ADS", "https://sils.unc.edu/academics/graduate/mas-applied-data-science/"),
    ("UNC ADS2", "https://sph.unc.edu/educ/masters-programs/"),
    # UNC Stats Analytics MS (Odgen?)
    ("UNC STAT", "https://stat.unc.edu/graduate-program/"),
    ("UNC STAT2", "https://stat.unc.edu/graduate/graduate-programs/"),
    # UNC BMI
    ("UNC BMI", "https://sph.unc.edu/bihi/"),
    ("UNC BMI2", "https://www.med.unc.edu//dbmi/"),
]
for name, url in candidates:
    st, n, body = get(url)
    print(f"{name:12s} {st} {n:>8}  {url}")
    if st == 200 and isinstance(body,str) and len(body) > 1000:
        # 抓关键信息
        title = re.search(r"<title>([^<]+)</title>", body, re.I)
        print("   title:", title.group(1).strip()[:100] if title else "?")
