# -*- 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")
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
hdr={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36"}
targets={
 "rice-caam":"https://ga.rice.edu/programs-study/departments-programs/engineering/computational-applied-mathematics-operations-research/",
 "rice-cse":"https://ga.rice.edu/programs-study/departments-programs/engineering/computational-science-engineering",
 "rice-ie":"https://ga.rice.edu/programs-study/departments-programs/engineering/industrial-engineering",
 "rice-mech":"https://ga.rice.edu/programs-study/departments-programs/engineering/mechanical-engineering",
 "rice-bioe":"https://ga.rice.edu/programs-study/departments-programs/engineering/bioengineering",
 "rice-meml":"https://ga.rice.edu/programs-study/departments-programs/engineering/engineering-management-leadership",
}
for k,u in targets.items():
    try:
        req=urllib.request.Request(u,headers=hdr)
        r=urllib.request.urlopen(req,context=ctx,timeout=20)
        b=r.read(); t=b.decode("utf-8","ignore")
        open(f"_rice11_{k}.html","wb").write(b)
        txt=re.sub(r"<script.*?</script>"," ",t,flags=re.S)
        txt=re.sub(r"<style.*?</style>"," ",txt,flags=re.S)
        txt=html.unescape(re.sub(r"<[^>]+>"," ",txt))
        txt=re.sub(r"\s+"," ",txt).strip()
        open(f"_rice11_{k}.txt","w",encoding="utf-8").write(txt)
        print(k,len(b),"B txt",len(txt))
    except Exception as e:
        print(k,"ERR",type(e).__name__,str(e)[:50])
