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")

h=fetch("https://socialsciences.uchicago.edu/admissions/application-materials/english-proficiency-requirements")
# rows
rows=re.findall(r'<tr[^>]*>(.*?)</tr>', h, flags=re.S|re.I)
for r in rows:
    cells=re.findall(r'<t[hd][^>]*>(.*?)</t[hd]>', r, flags=re.S|re.I)
    cells=[re.sub(r'\s+',' ',re.sub(r'<[^>]+>',' ',c)).strip() for c in cells]
    if any(cells):
        print(" | ".join(cells))

print("\n===== DEADLINES TABLE =====")
h2=fetch("https://socialsciences.uchicago.edu/admissions/deadlines-decisions")
rows2=re.findall(r'<tr[^>]*>(.*?)</tr>', h2, flags=re.S|re.I)
for r in rows2:
    cells=re.findall(r'<t[hd][^>]*>(.*?)</t[hd]>', r, flags=re.S|re.I)
    cells=[re.sub(r'\s+',' ',re.sub(r'<[^>]+>',' ',c)).strip() for c in cells]
    if any(cells): print(" | ".join(cells))
# dump text around MA rounds
t=re.sub(r'<script.*?</script>',' ',h2,flags=re.S|re.I); t=re.sub(r'<[^>]+>',' ',t); t=re.sub(r'\s+',' ',t)
i=t.lower().find('master')
for m in re.finditer(r'(Round\s*\d|January|February|March|November|December|October)[^.]{0,120}', t):
    print("DL>", m.group(0).strip())
