# -*- 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={
 "ischool":"https://ischool.illinois.edu/academics/graduate/ms-information-management",
 "duke-medphys":"https://medicalphysics.duke.edu/",
 "umich-mhi":"https://si.umich.edu/programs/degree-programs/master-health-informatics",
 "dart-meng":"https://engineering.dartmouth.edu/graduate/meng",
 "dart-mem":"http://engineering.dartmouth.edu/academics/graduate/mem/",
 "dart-ms":"http://engineering.dartmouth.edu/academics/graduate/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"})
        r=urllib.request.urlopen(req,context=ctx,timeout=15)
        b=r.read(); t=html.unescape(b.decode("utf-8","ignore"))
        open(f"_rice13_{k}.html","w",encoding="utf-8").write(t)
        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)
        links=re.findall(r'href="([^"]*(?:admission|tuition|deadline|requirement|apply)[^"]*)"',t)
        print(k,"200",len(b),"B  adm-links:",list(dict.fromkeys(links))[:6])
    except Exception as e:
        print(k,"ERR",type(e).__name__,str(e)[:60])
