# -*- coding: utf-8 -*-
import io,sys,ssl,urllib.request,re,html
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 get(u):
    try:
        req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
        b=urllib.request.urlopen(req,timeout=20,context=ctx).read()
        return b.decode("utf-8","ignore"),len(b)
    except Exception as e:
        return "ERR "+repr(e),0
def block(t,anchor,ln=2200):
    i=t.find(anchor)
    if i<0: return "(not found)"
    seg=re.sub(r"<script.*?</script>"," ",t[i:i+7000],flags=re.S)
    seg=html.unescape(re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",seg)))
    return seg[:ln]
u="https://e-catalogue.jhu.edu/engineering/full-time-residential-programs/degree-programs/applied-mathematics-statistics/financial-mathematics-master-science-engineering/"
t,n=get(u); print("LEN",n)
if not t.startswith("ERR"):
    print("### REQUIREMENTS\n",block(t,'id="requirementstextcontainer"'))
    print("\n### ADMISSION\n",block(t,'id="admissiontextcontainer"',1200))
    print("\n### TITLE/HEAD")
    c=html.unescape(re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",re.sub(r"<script.*?</script>"," ",t[:3000],flags=re.S))))
    print(c[:400])
