# -*- coding: utf-8 -*-
import io, sys, urllib.request, ssl, re, os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE

def fetch(url):
    req=urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
    r=urllib.request.urlopen(req, timeout=15, context=ctx)
    return r.read().decode("utf-8","ignore")

def clean(body):
    t = re.sub(r"<script[\s\S]*?</script>","",body)
    t = re.sub(r"<style[\s\S]*?</style>","",t)
    t = re.sub(r"<[^>]+>"," ",t)
    return re.sub(r"\s+"," ",t)

pages = {
    "unc_cs": "https://catalog.unc.edu/graduate/schools-departments/computer-science/",
    "unc_ds": "https://catalog.unc.edu/graduate/schools-departments/data-information-sciences/",
    "unc_bme": "https://catalog.unc.edu/graduate/schools-departments/biomedical-engineering/",
    "unc_crp": "https://catalog.unc.edu/graduate/schools-departments/city-regional-planning/",
    "rice_mai": "https://csweb.rice.edu/academics/graduate-programs/master-artificial-intelligence",
}
for k,u in pages.items():
    body = fetch(u)
    t = clean(body)
    # find Master's Degree section
    idx = t.find("Master's Degree")
    if idx<0: idx = t.find("Master of")
    if idx<0: idx = t.find("Master Degree")
    print(f"\n===== {k} =====")
    if idx>=0:
        print(t[idx:idx+1800])
    else:
        print("(no Master's section found)")
