# -*- 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
u="https://bulletin.stanford.edu/programs/EE-MS"
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")
c=html.unescape(re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",re.sub(r"<script.*?</script>"," ",t,flags=re.S))))
for kw in ["Program Overview","Degree Requirements","Depth Requirements","Breadth Requirements","Research Report","Preparation","undergraduate degrees"]:
    i=c.find(kw)
    print("\n===== ["+kw+"] =====\n", c[i:i+520] if i>=0 else "未命中")
# 方向 area 列表
for m in re.finditer(r"(Circuits|Signal Processing|Communications|Control|Electromagnetics|Optics|Photonics|Solid State|Electronics|Microelectronics|Nanoscale|Bioelectronics|Machine Learning|Computational|Energy|Power)[^,.;]{0,40}",c):
    print("AREA:",m.group(0)[:70])
