# -*- coding: utf-8 -*-
import io, sys, os, json, urllib.request, ssl, re, html
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
todo={x["det"]:x for x in json.load(open("todo_upgrade.json",encoding="utf-8"))}
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
x=todo["details/usc-ca09c65.html"]
print("AM url",x["url"])
req=urllib.request.Request(x["url"],headers={"User-Agent":"Mozilla/5.0"})
r=urllib.request.urlopen(req,timeout=15,context=ctx); b=r.read()
t=b.decode("utf-8","ignore")
t=re.sub(r'<script[\s\S]*?</script>',' ',t); t=re.sub(r'<style[\s\S]*?</style>',' ',t)
t=re.sub(r'<[^>]+>',' ',t); t=html.unescape(t); t=re.sub(r'\s+',' ',t)
open("_usc5_am.txt","w",encoding="utf-8").write(t)
print("status",r.status,"text",len(t))
# comds 子页链接
c=open("_usc5_comds.html","rb").read().decode("utf-8","ignore")
print("--- comds links ---")
for m in re.finditer(r'href="([^"]+)"',c):
    u=html.unescape(m.group(1))
    if "annenberg" in u.lower() and any(k in u.lower() for k in ["admiss","application","tuition","graduate","comm","master"]):
        print(u)
