# -*- 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={
 "duke-mp-req":"https://medicalphysics.duke.edu/program/degree-requirements/",
 "duke-mp-pre":"https://medicalphysics.duke.edu/admissions/admissions-prerequisites/",
 "duke-mp-adm":"https://medicalphysics.duke.edu/admissions/overview/",
 "duke-mp-stat":"https://medicalphysics.duke.edu/program/stats-on-admission/",
}
for k,u in urls.items():
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
        r=urllib.request.urlopen(req,context=ctx,timeout=15); b=r.read(); t=html.unescape(b.decode("utf-8","ignore"))
        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,r.status,len(b),"B")
    except Exception as e:
        print(k,"ERR",type(e).__name__,str(e)[:50])
