# -*- coding: utf-8 -*-
import io, sys, os, re, html, json, ssl, urllib.request
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
# MSE track 段
b=open("_33_jhu-c1d5ed0.html","rb").read()
txt=html.unescape(re.sub(r"<script[\s\S]*?</script>|<style[\s\S]*?</style>"," ",b.decode("utf-8","ignore")))
txt=re.sub(r"<[^>]+>"," ",txt); txt=re.sub(r"\s+"," ",txt)
i=txt.find("five tracks",50615)
print("=== MSE tracks ===")
print(txt[i:i+1400])
print()
# 探活 Duke Med Phys + UPenn Math MA
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
todo=json.load(open("todo_upgrade.json",encoding="utf-8"))
items=todo["list"] if isinstance(todo,dict) else todo
probe=[]
for x in items:
    det=x.get("det","") or ""
    en=x.get("en","") or ""
    s=x.get("s","")
    if s=="duke" and "medical-physics" in det:
        probe.append(("duke-med-phys",x.get("url",""),det.split("/")[-1]))
    if s=="up" and "mathematics" in en.lower() and x.get("deg")=="MA":
        probe.append(("up-math-ma",x.get("url",""),det.split("/")[-1]))
for label,u,base in probe:
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
        r=urllib.request.urlopen(req,timeout=10,context=ctx)
        bb=r.read()
        tt=html.unescape(re.sub(r"<[^>]+>"," ",bb.decode("utf-8","ignore")))
        tt=re.sub(r"\s+"," ",tt)
        open("_33_"+base,"wb").write(bb)
        print(label,r.status,len(bb),"textlen",len(tt),base)
    except Exception as e:
        print(label,"ERR",e,u)
