# -*- 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
P=[
 ("gscm","https://www.marshall.usc.edu/programs/graduate-programs/specialized-masters/ms-global-supply-chain-management-old"),
 ("macc","https://www.marshall.usc.edu/programs/graduate-programs/accounting-masters/master-of-accounting"),
 ("mkt","https://www.marshall.usc.edu/programs/graduate-programs/posts/ms-marketing-msmkt-archived"),
 ("comds","https://annenberg.usc.edu/communication/communication-data-science-ms"),
 ("ecods","https://dornsife.usc.edu/mecds/"),
]
def clean(b):
    t=b.decode("utf-8","ignore")
    t=re.sub(r'<script[\s\S]*?</script>',' ',t)
    t=re.sub(r'<style[\s\S]*?</style>',' ',t)
    t=re.sub(r'<[^>]+>',' ',t)
    t=html.unescape(t)
    t=re.sub(r'\s+',' ',t)
    return t
for tag,url in P:
    try:
        req=urllib.request.Request(url,headers={"User-Agent":"Mozilla/5.0"})
        r=urllib.request.urlopen(req,timeout=15,context=ctx); b=r.read()
        open(f"_usc5_{tag}.html","wb").write(b)
        open(f"_usc5_{tag}.txt","w",encoding="utf-8").write(clean(b))
        print(tag,r.status,len(b),"B")
    except Exception as e:
        print(tag,"ERR",type(e).__name__,str(e)[:60])
