# -*- coding: utf-8 -*-
import urllib.request, ssl, socket, io, sys, os, re, json
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
socket.setdefaulttimeout(20)
items = [
    ("usc-msba", "https://www.marshall.usc.edu/programs/graduate-programs/specialized-masters/ms-business-analytics"),
    ("usc-msf", "https://www.marshall.usc.edu/programs/graduate-programs/specialized-masters/ms-finance"),
    ("usc-stats", "https://dornsife.usc.edu/statsms/"),
    ("usc-apmath", "https://dornsife.usc.edu/mathematics/graduate/degree-requirements/"),
]
for key, u in items:
    try:
        req = urllib.request.Request(u, headers={"User-Agent":"Mozilla/5.0"})
        r = urllib.request.urlopen(req, context=SCTX, timeout=20)
        body = r.read().decode("utf-8", errors="ignore")
        txt = re.sub(r"<script[\s\S]*?</script>", " ", body)
        txt = re.sub(r"<style[\s\S]*?</style>", " ", txt)
        txt = re.sub(r"<[^>]+>", " ", txt)
        txt = re.sub(r"\s+", " ", txt)
        # 找正文：跳过导航，找 "About" 或 "Curriculum" 或 "Program" 之后
        print(f"\n========== {key} {r.status} {len(body)} ==========")
        # 输出中间段（8000-20000）
        print(txt[8000:20000])
    except Exception as e:
        print(f"ERR {key} {e}")
