# -*- coding: utf-8 -*-
import urllib.request, ssl, sys, io, re, html
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
SCTX = ssl.create_default_context(); SCTX.check_hostname=False; SCTX.verify_mode=ssl.CERT_NONE
urls = [
    ("MEB", "https://dornsife.usc.edu/bisc/graduate/masters-programs/"),
    ("CMB", "https://www.qcb-dornsife.usc.edu/masters"),
    ("DLA", "https://rossier.usc.edu/programs/masters/data-science-for-learning-applications/"),
    ("UCHI_BMI", "https://bmi.bsd.uchicago.edu/"),
    ("GTECH_BCFM", "https://catalog.gatech.edu/programs/building-construction-facility-management-ms/"),
]
for name, u in urls:
    req = urllib.request.Request(u, headers={"User-Agent":"Mozilla/5.0"})
    with urllib.request.urlopen(req, timeout=15, context=SCTX) as r:
        body = r.read().decode("utf-8", errors="ignore")
    body = re.sub(r"<script[\s\S]*?</script>", " ", body, flags=re.I)
    body = re.sub(r"<style[\s\S]*?</style>", " ", body, flags=re.I)
    body = re.sub(r"<nav[\s\S]*?</nav>", " ", body, flags=re.I)
    text = re.sub(r"<[^>]+>", " ", body)
    text = html.unescape(text); text = re.sub(r"\s+", " ", text).strip()
    print("="*80); print(name, u, "len", len(text))
    print(text[:2500])
