# -*- 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={t["det"].split("/")[-1]:t for t 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
def fetch(url):
    req=urllib.request.Request(url,headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"})
    r=urllib.request.urlopen(req,timeout=15,context=ctx); b=r.read(); return b.decode("utf-8","ignore")
for key in ["cmu-c2ee442.html","cmu-c8e8fa0.html","cmu-c274a8e.html","cmu-cdd17fa.html","cmu-c46c856.html"]:
    t=todo[key]
    h=fetch(t["url"])
    open("_cmu10_"+key,"w",encoding="utf-8").write(h)
    # 去标签抽文本
    txt=re.sub(r"<script.*?</script>","",h,flags=re.S|re.I)
    txt=re.sub(r"<style.*?</style>","",txt,flags=re.S|re.I)
    txt=html.unescape(re.sub(r"<[^>]+>"," ",txt))
    txt=re.sub(r"\s+"," ",txt).strip()
    open("_cmu10_"+key+".txt","w",encoding="utf-8").write(txt)
    print("====",key,t["en"][:40],"len",len(txt))
    print(txt[:600])
    print()
