# -*- coding: utf-8 -*-
import io, sys, os, re, json, urllib.request, ssl
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
idx=open("index_main.html",encoding="utf-8").read()
catd=idx[idx.find("const CATD="):idx.find("const VERIFIED_DETAILS=")]
targets=["chemical-biomolecular","civil-environmental","electrical-computer","materials-science","mechanical-engineering","master-of-engineering-degree-cps","master-of-engineering-degree-esi"]
for t in targets:
    for line in catd.split("\n"):
        if t in line:
            m=re.search(r'\["([^"]+)","([^"]*)","([^"]+)","([^"]*)","([^"]*)","([^"]+)","([^"]*)","([^"]*)"',line)
            if m:
                print(t,"|",m.group(3),"|",m.group(5),"|",m.group(6),"|",m.group(8))
            break

ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
urls={
 "ECE":"https://engineering.vanderbilt.edu/departments/electrical-computer-engineering/graduate-programs/",
 "ME":"https://engineering.vanderbilt.edu/departments/mechanical-engineering/graduate-programs/",
 "CBE":"https://engineering.vanderbilt.edu/departments/chemical-biomolecular-engineering/graduate-programs/",
 "CPS":"https://engineering.vanderbilt.edu/academics/master-of-engineering-degree-cps/",
 "ESI":"https://engineering.vanderbilt.edu/academics/master-of-engineering-degree-esi/",
}
for k,u in urls.items():
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
        r=urllib.request.urlopen(req,timeout=12,context=ctx); b=r.read(); print(k,r.status,len(b),u)
        open("_17_"+k.lower()+".txt","wb").write(b)
    except Exception as e:
        print(k,"ERR",type(e).__name__,str(e)[:80],u)
