# -*- coding: utf-8 -*-
import io, sys, os, json, re, ssl, urllib.request, html
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")

def clean(b):
    txt=html.unescape(re.sub(r"<script[\s\S]*?</script>|<style[\s\S]*?</style>"," ",b.decode("utf-8","ignore")))
    txt=re.sub(r"<[^>]+>"," ",txt); return re.sub(r"\s+"," ",txt)

for f in ["_32_notre-cee-meng.html","_32_jhu-ehe-ms.html"]:
    b=open(f,"rb").read(); txt=clean(b)
    print("====",f,"text",len(txt))
    print(txt[1200:3400])
    print()

# 补抓 MSEnvE
todo=json.load(open("todo_upgrade.json",encoding="utf-8"))
items=todo["list"] if isinstance(todo,dict) else todo
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
for x in items:
    det=os.path.basename(x.get("det",""))
    if det=="notre-civil-engineering-msenve---masters-traditional.html":
        u=x["url"]
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
        r=urllib.request.urlopen(req,timeout=10,context=ctx); b=r.read()
        open("_32_notre-msenve.html","wb").write(b)
        txt=clean(b)
        print("==== MSEnvE",r.status,len(b),"text",len(txt)); print(txt[:1600])
