# -*- 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")
probe={x["det"]:x for x in json.load(open("_probe30b.json",encoding="utf-8"))}
pick=["up-c1fcccb.html","up-c20664c.html","up-c0a3bf1.html","up-c775b37.html","up-c4be16d.html",
      "uw-c435976.html","uw-cb1d654.html","uw-cb1705c.html"]
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
for det in pick:
    x=probe[det]; url=x["url"]
    try:
        req=urllib.request.Request(url,headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"})
        r=urllib.request.urlopen(req,timeout=10,context=ctx)
        b=r.read(); txt=html.unescape(b.decode("utf-8","ignore"))
        open("_30_"+det,"wb").write(b)
        plain=re.sub(r"<script[\s\S]*?</script>"," ",txt)
        plain=re.sub(r"<style[\s\S]*?</style>"," ",plain)
        plain=re.sub(r"<[^>]+>"," ",plain)
        plain=re.sub(r"\s+"," ",plain)
        kws=["credit","thesis","non-thesis","course unit","degree requirement","concentration","specialization","track","deadline","TOEFL","IELTS","GRE","tuition","STEM","full-time","part-time","online","co-op","Co-op","advisor","prerequisite","undergraduate"]
        hits=[plain[max(0,m.start()-60):m.start()+160] for m in re.finditer("|".join(kws),plain)][:12]
        print("\n====",det,x["en"],r.status,len(b))
        for h in hits: print("  •",h.strip()[:200])
    except Exception as e:
        print("\n====",det,"ERR",type(e).__name__,str(e)[:80])
