# -*- coding: utf-8 -*-
import urllib.request, ssl, re, sys, io
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
for name, url in [
 ("UNC_Ling", "https://catalog.unc.edu/graduate/schools-departments/linguistics/"),
 ("UNC_Drama", "https://catalog.unc.edu/graduate/schools-departments/dramatic-art/"),
]:
    req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
    r = urllib.request.urlopen(req, timeout=15, context=SCTX)
    b = r.read().decode("utf-8", errors="ignore")
    text = re.sub(r"<script[\s\S]*?</script>", " ", b, flags=re.I)
    text = re.sub(r"<style[\s\S]*?</style>", " ", text, flags=re.I)
    text = re.sub(r"<[^>]+>", " ", text)
    text = re.sub(r"\s+", " ", text).strip()
    print(f"=== {name} ===")
    # 找 "Graduate" 段
    m = re.search(r"Graduate[^\n]{0,5000}", text)
    if m:
        print(m.group(0)[:3000])
    print()
