import ssl, urllib.request, re, sys, io
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 fetch(u):
    req=urllib.request.Request(u, headers={"User-Agent":"Mozilla/5.0"})
    return urllib.request.urlopen(req, context=ctx, timeout=25).read().decode("utf-8","ignore")
def text(h):
    h=re.sub(r'<script.*?</script>',' ',h,flags=re.S|re.I); h=re.sub(r'<style.*?</style>',' ',h,flags=re.S|re.I)
    h=re.sub(r'<[^>]+>',' ',h); h=re.sub(r'&nbsp;',' ',h); h=re.sub(r'&amp;','&',h); h=re.sub(r'\s+',' ',h)
    return h.strip()
u="https://advancedscholars.uchicago.edu/participating-programs/"
h=fetch(u)
links=sorted(set(re.findall(r'href="([^"]+)"',h)))
for l in links:
    if re.search(r'(econ|mae|ma-\d|program)',l,re.I): print(l)
t=text(h)
i=t.lower().find('economics')
print("---- context ----")
print(t[max(0,i-200):i+700])
