# -*- 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://uwaterloo.ca/future-graduate-students/programs/by-faculty/engineering/systems-design-engineering-master-applied-science-masc"
req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
t=urllib.request.urlopen(req,timeout=20,context=ctx).read().decode("utf-8","ignore")
def clean(x):
    x=re.sub(r"<script.*?</script>"," ",x,flags=re.S); x=re.sub(r"<style.*?</style>"," ",x,flags=re.S)
    x=re.sub(r"<[^>]+>"," ",x); x=re.sub(r"&nbsp;"," ",x); x=re.sub(r"&amp;","&",x); x=re.sub(r"&#39;","'",x)
    return re.sub(r"\s+"," ",x)
c=clean(t)
j=c.find("Admission requirements")
print("[req]",c[j:j+520]); print()
k=c.find("Application materials")
print("[mat]",c[k:k+420]); print()
m=c.find("Research fields")
print("[fields]",c[m:m+300] if m>0 else "no fields")
n=c.find("Note:")
if n>0: print("[note]",c[n:n+160])
