# -*- coding: utf-8 -*-
import io, sys, os, re, html, urllib.request, ssl
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()
def fetch(url,fn):
    req=urllib.request.Request(url,headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"})
    b=urllib.request.urlopen(req,timeout=15,context=ctx).read()
    t=b.decode("utf-8","ignore")
    open(fn,"w",encoding="utf-8").write(t)
    txt=html.unescape(re.sub(r"<script.*?</script>","",t,flags=re.S))
    txt=html.unescape(re.sub(r"<style.*?</style>","",txt,flags=re.S))
    txt=re.sub(r"<[^>]+>"," ",txt)
    txt=re.sub(r"\s+"," ",txt)
    return len(b),txt

for name,url in [
 ("vandy-mfin","https://business.vanderbilt.edu/masters-in-finance/"),
 ("vandy-mm","https://business.vanderbilt.edu/master-of-management/"),
 ("vandy-mmkt","https://business.vanderbilt.edu/master-of-marketing/"),
]:
    try:
        n,t=fetch(url,"_17_"+name+".txt")
        print("="*15,name,n)
        print(t[:2600])
    except Exception as e:
        print(name,"ERR",type(e).__name__,str(e)[:60])
