# -*- coding: utf-8 -*-
import ssl, urllib.request, re, io, sys
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://gradschool.duke.edu/academics/programs-degrees/electrical-and-computer-engineering-ms/",
 "https://ece.duke.edu/graduate/masters",
 "https://ece.duke.edu/graduate",
]
def strip(h):
    h=re.sub(r"<script[\s\S]*?</script>","",h); h=re.sub(r"<style[\s\S]*?</style>","",h)
    h=re.sub(r"<[^>]+>"," ",h); h=re.sub(r"\s+"," ",h); return h.strip()
for u in urls:
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
        raw=urllib.request.urlopen(req,context=ctx,timeout=20).read()
        t=raw.decode("utf-8","ignore")
        print("OK",u,"bytes=",len(raw),"text=",len(strip(t)))
    except Exception as e:
        print("ERR",u,repr(e)[:160])
