# -*- 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="https://grad.uchicago.edu/programs/computer-science/"
req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
d=urllib.request.urlopen(req,context=ctx,timeout=20).read().decode("utf-8","ignore")
seg=d[869740:1016358]
h=re.sub(r"<script.*?</script>"," ",seg,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("SEG TEXT LEN",len(t)); print(t[:3000])
# entry-content 内的外链
links=re.findall(r'href="([^"]+)"',seg)
print("\nLINKS:")
for x in sorted(set(links)):
    if "mailto" not in x: print("  ",x)
