# -*- 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
pages={
 "math_req":"https://dornsife.usc.edu/mathematics/degree-requirements/",
 "math_adm":"https://dornsife.usc.edu/mathematics/admissions/",
 "mcg_cur":"https://annenberg.usc.edu/academics/communication-mcm/curriculum",
 "mcg_adm":"https://annenberg.usc.edu/admissions/graduate-applicants/mcg-communication-management",
 "mitle_app":"https://gould.usc.edu/academics/degrees/mitle/application/",
 "niin_pro":"https://niin.usc.edu/students/prospective-students",
}
for k,u in pages.items():
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
        b=urllib.request.urlopen(req,timeout=15,context=ctx).read()
        t=html.unescape(re.sub(r"<script.*?</script>","",b.decode("utf-8","ignore"),flags=re.S))
        t=re.sub(r"<style.*?</style>","",t,flags=re.S); t=re.sub(r"<[^>]+>"," ",t); t=re.sub(r"\s+"," ",t)
        open("_usc7_"+k+".txt","w",encoding="utf-8").write(t)
        print(k,len(b),"B txt",len(t))
    except Exception as e:
        print(k,"ERR",type(e).__name__,str(e)[:40])
