# -*- coding: utf-8 -*-
import io, sys, os, urllib.request, ssl, html, re
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
urls={
 "ill-im":"https://catalog.illinois.edu/graduate/is/information-management-ms/",
 "ill-econ":"https://catalog.illinois.edu/graduate/las/economics-ms/",
 "ill-pecon":"https://catalog.illinois.edu/graduate/las/policy-economics-ms",
 "ill-aae":"https://catalog.illinois.edu/graduate/aces/agricultural-applied-economics-ms/",
}
for k,u in urls.items():
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"})
        b=urllib.request.urlopen(req,context=ctx,timeout=15).read()
        t=html.unescape(b.decode("utf-8","ignore"))
        open(f"_rice13_{k}.html","w",encoding="utf-8").write(t)
        # strip tags rough
        txt=re.sub(r"<script.*?</script>","",t,flags=re.S)
        txt=re.sub(r"<style.*?</style>","",txt,flags=re.S)
        txt=re.sub(r"<[^>]+>"," ",txt)
        txt=re.sub(r"\s+"," ",txt)
        open(f"_rice13_{k}.txt","w",encoding="utf-8").write(txt)
        print(k,"200",len(b),"B txt",len(txt))
    except Exception as e:
        print(k,"ERR",type(e).__name__,str(e)[:60])
