# -*- coding: utf-8 -*-
import io,sys,ssl,urllib.request,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
u="http://grad.uchicago.edu/programs/computer-science/"
req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
r=urllib.request.urlopen(req,context=ctx,timeout=20)
d=r.read().decode("utf-8","ignore")
print("FINAL",r.status,r.geturl(),"rawlen",len(d))
links=re.findall(r'href="([^"]+)"',d)
rel=[x for x in links if ("cs.uchicago" in x or "computer" in x) and "mailto" not in x]
print("LINKS:")
for x in sorted(set(rel)): print("  ",x)
h=re.sub(r"<script.*?</script>"," ",d,flags=re.S|re.I); h=re.sub(r"<style.*?</style>"," ",h,flags=re.S|re.I)
t=re.sub(r"<[^>]+>"," ",h); t=re.sub(r"&nbsp;|&#x27;|&amp;|&#8217;|&#038;|&#8203;|&#8211;|&#039;"," ",t); t=re.sub(r"\s+"," ",t)
print("\nTEXT LEN",len(t)); print(t[:3500])
