import re, os, sys, io, urllib.request, ssl, socket
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
base = os.path.dirname(os.path.abspath(__file__))
det = {
 "notre-cse-mscse":"details/notre-cse-mscse.html",
 "notre-ee-msee":"details/notre-ee-msee.html",
 "notre-ms-acms":"details/notre-ms-applied-computational-math-statistics.html",
 "jhu-finecon":"details/jhu-finecon.html",
 "jhu-bioinfo-ms":"details/jhu-bioinfo-ms.html",
 "jhu-gis-ms":"details/jhu-gis-ms.html",
 "usc-stats-ms":"details/usc-stats-ms.html",
 "usc-aeec-ms":"details/usc-aeec-ms.html",
 "usc-seda-ms":"details/usc-seda-ms.html",
 "usc-apmath-ms":"details/usc-apmath-ms.html",
 "illinois-mspe":"details/illinois-mspe.html",
 "ubc-mppga":"details/ubc-mppga.html",
 "ut-mmpa":"details/ut-mmpa.html",
 "ut-mmi":"details/ut-mmi.html",
}
ctx = ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
def probe(url):
    try:
        req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"})
        with urllib.request.urlopen(req, timeout=10, context=ctx) as resp:
            body = resp.read(40000).decode("utf-8","ignore")
            return resp.status, len(body)
    except urllib.error.HTTPError as e:
        return e.code, 0
    except Exception as e:
        return "ERR", str(e)[:60]

for bid, d in det.items():
    p = os.path.join(base, d.replace("/", os.sep))
    urls = []
    if os.path.exists(p):
        html = open(p, encoding="utf-8", errors="ignore").read()
        urls = re.findall(r'https?://[^"\'<>\s]+', html)
        # 过滤 CDN/字体/file
        urls = [u for u in urls if not any(x in u for x in ["fonts.googleapis","fonts.gstatic","file://","googleapis","gstatic","cloudflare","jquery"])]
    # 去重保序
    seen=set(); urls=[u for u in urls if not (u in seen or seen.add(u))]
    print(f"[{bid}] {d}")
    for u in urls[:4]:
        st, info = probe(u)
        print(f"   {st} {info}  {u}")
    print()
