# -*- coding: utf-8 -*-
import io,sys,urllib.request,ssl,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
url="https://uwaterloo.ca/future-graduate-students/programs/by-faculty/science/physics-master-science-msc"
req=urllib.request.Request(url,headers={"User-Agent":"Mozilla/5.0"})
try:
    raw=urllib.request.urlopen(req,timeout=25,context=ctx).read()
    t=raw.decode("utf-8","ignore")
    print("LEN",len(t))
    # 去标签取正文
    body=re.sub(r"<script[\s\S]*?</script>"," ",t)
    body=re.sub(r"<style[\s\S]*?</style>"," ",body)
    body=re.sub(r"<[^>]+>"," ",body)
    body=html.unescape(re.sub(r"\s+"," ",body)).strip()
    for kw in ["Program type","Delivery","Duration","Full-time","Part-time","Admission","average","TOEFL","IELTS","GRE","deadline","Deadline","Supervisor","Thesis","Research Paper","Coursework","Tuition","Funding","recommendation","statement","resume","Resume","letter"]:
        for m in re.finditer(r"[^.]*"+re.escape(kw)+r"[^.]*\.?",body):
            seg=m.group(0).strip()
            if len(seg)<260: print("·",seg)
except Exception as e:
    print("ERR",type(e).__name__,e)
