import os, ssl, urllib.request, html, re
BASE = os.path.dirname(os.path.abspath(__file__))
ctx = ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
targets = [
 ("wustl-stats", "https://bulletin.wustl.edu/grad/artsci/degrees/stats-data-science-polsci-conc-ma/"),
 ("rice-macc", "https://ga.rice.edu/programs-study/departments-programs/business/accounting"),
 ("mit-mban", "https://oge.mit.edu/programs/mit-sloan-master-of-business-analytics/"),
]
def clean(raw):
    t = re.sub(r'<script[\s\S]*?</script>',' ',raw); t=re.sub(r'<style[\s\S]*?</style>',' ',t)
    t=re.sub(r'<[^>]+>',' ',t); return html.unescape(re.sub(r'\s+',' ',t)).strip()
for tag,url in targets:
    try:
        req=urllib.request.Request(url,headers={'User-Agent':'Mozilla/5.0'})
        with urllib.request.urlopen(req,timeout=12,context=ctx) as r:
            b=r.read(); raw=b.decode('utf-8','replace')
        open(os.path.join(BASE,f'_25_{tag}.txt'),'w',encoding='utf-8').write(raw)
        txt=clean(raw)
        print('='*20,tag,r.status,'bytes',len(b),'text',len(txt))
        print(txt[:1400]); print()
    except Exception as e:
        print('='*20,tag,'FAIL',type(e).__name__,e)
