# -*- coding: utf-8 -*-
import urllib.request, ssl, sys, io, re, html
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
SCTX = ssl.create_default_context()
SCTX.check_hostname = False
SCTX.verify_mode = ssl.CERT_NONE
UA = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36"}
pages = [
 ("up-sci-comp","https://catalog.upenn.edu/graduate/programs/scientific-computing-mse/"),
 ("up-mbiot","https://catalog.upenn.edu/graduate/programs/biotechnology-mbiot/"),
]
for tag,url in pages:
    req = urllib.request.Request(url, headers=UA)
    r = urllib.request.urlopen(req, timeout=15, context=SCTX)
    body = r.read().decode("utf-8","ignore")
    txt = re.sub(r'<script[\s\S]*?</script>', ' ', body, flags=re.I)
    txt = re.sub(r'<style[\s\S]*?</style>', ' ', txt, flags=re.I)
    txt = re.sub(r'<[^>]+>', ' ', txt)
    txt = html.unescape(txt)
    txt = re.sub(r'\s+', ' ', txt)
    print(f"\n========== {tag} ==========")
    m = re.search(r'(Curriculum|Program of Study|Degree Requirements).{0,2200}', txt)
    if m: print(m.group(0)[:2200])
