import re, sys, io, urllib.request, ssl
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
ctx = ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
def get(url):
    req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
    with urllib.request.urlopen(req, timeout=12, context=ctx) as resp:
        return resp.status, resp.read().decode("utf-8","ignore")

pages = {
 "ACMS-MS":"https://graduateschool.nd.edu/degree-programs/applied-and-computational-mathematics-and-statistics-ms---masters-professional/",
 "CSE-MSCSE":"https://graduateschool.nd.edu/degree-programs/computer-science-and-engineering-mscse---masters-professional/",
 "EE-MSEE":"https://graduateschool.nd.edu/degree-programs/electrical-engineering-msee---masters-traditional/",
}
for k,u in pages.items():
    try:
        st, body = get(u)
        print(f"=== {k}  HTTP {st} len {len(body)} ===")
        txt = re.sub(r'<script[\s\S]*?</script>','',body)
        txt = re.sub(r'<style[\s\S]*?</style>','',txt)
        txt = re.sub(r'<[^>]+>',' ',txt)
        txt = re.sub(r'\s+',' ',txt)
        for kw in ["tuition","per credit","credit hour","fee","cost","scholarship","assistantship","financial","$"]:
            for m in re.finditer(r'[^.]*'+kw+r'[^.]*\.?', txt, re.I):
                seg=m.group(0).strip()
                if seg: print("  -", seg[:140])
        print()
    except Exception as e:
        print(f"{k} ERR {e}\n")
