# -*- coding: utf-8 -*-
import ssl, urllib.request, io, sys, re
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
urls=[
 "https://catalog.cornell.edu/programs/information-systems-ms/",
 "https://tech.cornell.edu/programs/masters-programs/data-science-decision-analytics/",
 "https://publicpolicy.cornell.edu/masters/dspp/",
 "https://web.gs.emory.edu/degree-programs/",
]
for u in urls:
    try:
        req=urllib.request.Request(u, headers={"User-Agent":"Mozilla/5.0"})
        r=urllib.request.urlopen(req, timeout=15, context=ctx)
        html=r.read().decode("utf-8","ignore")
        title=re.search(r"<title>(.*?)</title>",html,re.S)
        txt=re.sub(r"<script.*?</script>"," ",html,flags=re.S)
        txt=re.sub(r"<[^>]+>"," ",txt)
        txt=re.sub(r"\s+"," ",txt).strip()
        print("OK",r.status,u,"len=",len(html),"text=",len(txt))
        print("  title=", (title.group(1).strip()[:90] if title else ""))
        print("  head=",txt[:260])
    except Exception as e:
        print("ERR",u,repr(e)[:140])
    print("-"*100)
