# -*- 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 probe(url, timeout=12):
    try:
        req=urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0"})
        r=urllib.request.urlopen(req, timeout=timeout, context=ctx)
        b=r.read(); return r.status, len(b), b.decode("utf-8","ignore")
    except Exception as e:
        return None, 0, str(e)

cands = [
    ("Rice grad degree list", "https://engineering.rice.edu/academics/graduate-programs/graduate-degree-programs"),
    ("Rice MSCS", "https://csweb.rice.edu/academics/graduate-programs/master-computer-science"),
    ("Rice MSDS", "https://csweb.rice.edu/academics/graduate-programs/master-data-science"),
    ("Rice MAI", "https://csweb.rice.edu/academics/graduate-programs/master-artificial-intelligence"),
    ("UNC grad degree list", "https://catalog.unc.edu/graduate/degree-programs/"),
    ("Brown programs-requirements", "https://graduateschool.brown.edu/index.php/academics/programs-requirements"),
]
for name, url in cands:
    s, n, body = probe(url)
    print(f"\n=== [{name}] {s} {n}B ===")
    if s==200 and n>3000:
        # strip tags
        text = re.sub(r"<script[\s\S]*?</script>","",body)
        text = re.sub(r"<style[\s\S]*?</style>","",text)
        text = re.sub(r"<[^>]+>"," ",text)
        text = re.sub(r"\s+"," ",text)
        print(text[:2500])
        # extract links
        links = re.findall(r'href="([^"]+)"', body)
        prog = [l for l in links if l.startswith("/") and re.search(r'(master|ms|m\.s|m\.eng|meng|program|degree)', l, re.I)]
        print("--- links ---")
        for l in prog[:25]:
            print("  ", l)
