# -*- 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
base="https://priceschool.usc.edu/academics/masters/master-of-science-in-public-policy-data-ppd/"
pages={"mppds_cur":"mppd-curriculum/","mppds_pre":"mppd-prerequisites/","mppds_adm":"mppd-admission/","mppds_tui":"mppds-tuition/"}
for tag,path in pages.items():
    u=base+path
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
        b=urllib.request.urlopen(req,timeout=15,context=ctx).read()
        txt=html.unescape(re.sub(r"<script.*?</script>"," ",b.decode("utf-8","ignore"),flags=re.S|re.I))
        txt=re.sub(r"<style.*?</style>"," ",txt,flags=re.S|re.I)
        txt=re.sub(r"<[^>]+>"," ",txt); txt=re.sub(r"\s+"," ",txt).strip()
        open(f"_usc6_{tag}.txt","w",encoding="utf-8").write(txt)
        print(tag,len(b),"B",len(txt),"txt")
    except Exception as e:
        print(tag,"ERR",type(e).__name__,str(e)[:50])
