# -*- coding: utf-8 -*-
import ssl, re, html, io, sys, urllib.request
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
H={"User-Agent":"Mozilla/5.0"}
def fetch(u):
    req=urllib.request.Request(u,headers=H)
    try:
        with urllib.request.urlopen(req,context=ctx,timeout=20) as r:
            b=r.read(); return r.status,b.decode("utf-8","ignore"),len(b)
    except Exception as e:
        return None,repr(e),0

URLS=[
 "https://gradschool.cornell.edu/admissions/prepare/english-language-proficiency-requirement/",
 "https://gradschool.cornell.edu/admissions/application-steps/required-tests/english-language-proficiency-requirement-2/",
 "https://publicpolicy.cornell.edu/masters/msdsp/residential/cost-and-aid/",
 "https://publicpolicy.cornell.edu/masters/dspp/dspp-cost-of-attendance/",
]
for u in URLS:
    st,txt,n=fetch(u)
    print("="*90); print(u,"->",st,"len",n)
    if st==200:
        body=html.unescape(re.sub(r"<[^>]+>"," ",re.sub(r"<script.*?</script>|<style.*?</style>"," ",txt,flags=re.S)))
        body=re.sub(r"\s+"," ",body)
        for kw in ["TOEFL","IELTS","Duolingo","score","Score","minimum","fee","Fee","tuition","Tuition","COA","Cost","$","waiver","Waiver","GRE","GMAT"]:
            for m in re.finditer(re.escape(kw),body):
                s=max(0,m.start()-90); e=min(len(body),m.end()+170)
                print(f"  [{kw}] ...{body[s:e]}..."); break
