# -*- coding: utf-8 -*-
import io, sys, os, json, urllib.request, ssl, html, re
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
todo={os.path.basename(t["det"]):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
cands=["cmu-c2ee442.html","cmu-c274a8e.html","cmu-c977e17.html","cmu-c8e8fa0.html","cmu-c46c856.html","rice-data-science.html"]
for c in cands:
    t=todo[c]
    try:
        req=urllib.request.Request(t["url"],headers={"User-Agent":"Mozilla/5.0"})
        b=urllib.request.urlopen(req,timeout=15,context=ctx).read()
        txt=html.unescape(re.sub(r"<script.*?</script>","",b.decode("utf-8","ignore"),flags=re.S))
        txt=re.sub(r"<style.*?</style>","",txt,flags=re.S); txt=re.sub(r"<[^>]+>"," ",txt); txt=re.sub(r"\s+"," ",txt)
        open("_o7_"+c.replace(".html","")+".txt","w",encoding="utf-8").write(txt)
        print(c,len(b),"B txt",len(txt))
    except Exception as e:
        print(c,"ERR",type(e).__name__,str(e)[:40])
