# -*- 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://stat.cornell.edu/master-professional-studies-applied-statistics/apply"
req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
d=urllib.request.urlopen(req,context=ctx,timeout=20).read().decode("utf-8","ignore")
h=re.sub(r"<script.*?</script>"," ",d,flags=re.S|re.I)
h=re.sub(r"<style.*?</style>"," ",h,flags=re.S|re.I)
t=re.sub(r"<[^>]+>"," ",h); t=re.sub(r"&nbsp;"," ",t); t=re.sub(r"\s+"," ",t)
print("GRE 出现次数:", len(re.findall(r"GRE",t)))
for m in re.finditer(r".{40}GRE.{80}",t): print(" GRE:",m.group(0).strip())
for m in re.finditer(r".{20}[Mm]inimum GPA.{60}",t): print(" GPA:",m.group(0).strip())
for m in re.finditer(r".{30}grade point.{60}",t,re.I): print(" GPA2:",m.group(0).strip())
# track 课程
u2="https://stat.cornell.edu/master-professional-studies-applied-statistics/academic-planning"
d2=urllib.request.urlopen(urllib.request.Request(u2,headers={"User-Agent":"Mozilla/5.0"}),context=ctx,timeout=20).read().decode("utf-8","ignore")
h2=re.sub(r"<script.*?</script>"," ",d2,flags=re.S|re.I); h2=re.sub(r"<style.*?</style>"," ",h2,flags=re.S|re.I)
t2=re.sub(r"<[^>]+>"," ",h2); t2=re.sub(r"&nbsp;"," ",t2); t2=re.sub(r"\s+"," ",t2)
for kw in ["Statistical Analysis track","Data Science track","core course","STSCI","probability","elective"]:
    for m in re.finditer(r".{10}"+re.escape(kw)+r".{100}",t2):
        print(" ["+kw+"]",m.group(0).strip()[:220]); break
