# -*- coding: utf-8 -*-
import io, sys, os, 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
def fetch(tag,u):
    req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/120 Safari/537.36","Accept":"text/html"})
    r=urllib.request.urlopen(req,timeout=20,context=ctx); b=r.read()
    open(f"_rice12_{tag}.html","wb").write(b)
    h=b.decode("utf-8","ignore"); h=re.sub(r"<script.*?</script>","",h,flags=re.S); h=re.sub(r"<style.*?</style>","",h,flags=re.S)
    t=html.unescape(re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",h)))
    open(f"_rice12_{tag}.txt","w",encoding="utf-8").write(t)
    print(tag,r.status,len(b),"B, text",len(t))
fetch("DukeQFE","https://gradschool.duke.edu/academics/programs-degrees/quantitative-financial-economics")
fetch("DartHDS","https://healthsciences.dartmouth.edu/education/degree-programs/master-science-health-data-science/compare")
