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 probe(url):
    try:
        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, len(resp.read()), resp.read().decode("utf-8","ignore")
    except urllib.error.HTTPError as e:
        return e.code, 0, ""
    except Exception as e:
        return "ERR", 0, str(e)[:60]

urls = [
 ("UBC-MPPGA-list","https://www.grad.ubc.ca/prospective-students/graduate-degree-programs"),
 ("UBC-MPPGA","https://www.grad.ubc.ca/prospective-students/graduate-degree-programs/master-public-policy-and-global-affairs"),
 ("JHU-GIS-cat","https://e-catalogue.jhu.edu/arts-sciences/advanced-academic-programs/programs/geographic-information-systems-master-science/"),
]
for k,u in urls:
    st, ln, body = probe(u)
    print(f"=== {k} HTTP {st} len {ln} ===")
    if st==200:
        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 m in re.finditer(r'[^.]*\$[\d,]+[^.]*\.?', txt):
            s=m.group(0).strip()
            if any(w in s.lower() for w in ["tuition","credit","fee","per","term","hour","cost","scholar"]):
                print("  $:", s[:150])
        for kw in ["tuition","per credit","credit hour","per course"]:
            for m in re.finditer(r'[^.]*'+kw+r'[^.]*\.?', txt, re.I):
                print("  -", m.group(0).strip()[:140])
    print()
