# -*- coding: utf-8 -*-
import urllib.request, ssl, sys, io, os, re
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
SCTX = ssl.create_default_context()
SCTX.check_hostname = False
SCTX.verify_mode = ssl.CERT_NONE
slugs = [
    "genetic-counseling-msgc",
    "clinical-epidemiology-msce",
    "healthcare-quality-safety-mhqs",
    "bioethics-mbe",
    "nutrition-science-msns",
]
H = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36",
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    "Accept-Language": "en-US,en;q=0.9",
    "Referer": "https://catalog.upenn.edu/graduate/programs/",
}
for slug in slugs:
    url = f"https://catalog.upenn.edu/graduate/programs/{slug}/"
    try:
        req = urllib.request.Request(url, headers=H)
        r = urllib.request.urlopen(req, timeout=20, context=SCTX)
        body = r.read().decode("utf-8", errors="replace")
        m = re.search(r"<title>(.*?)</title>", body, re.S)
        title = m.group(1).strip() if m else "?"
        print(f"{slug}  status={r.status}  len={len(body)}  title={title[:80]}")
    except Exception as e:
        print(f"{slug}  ERR {e}")
