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

SCTX = ssl.create_default_context()
SCTX.check_hostname = False
SCTX.verify_mode = ssl.CERT_NONE

# Duke MSEC: 从 econ.duke.edu/masters/ 找具体链接
print("=== Duke econ.duke.edu/masters/ ===")
try:
    req = urllib.request.Request("https://econ.duke.edu/masters/", headers={"User-Agent": "Mozilla/5.0"})
    html = urllib.request.urlopen(req, timeout=15, context=SCTX).read().decode("utf-8", errors="ignore")
    print("size:", len(html))
    links = re.findall(r'href="([^"]*(?:economics-computation|msec|masters|graduate)[^"]*)"[^>]*>([^<]{2,60})<', html, re.I)
    for href, txt in links[:20]:
        print(f"  {href[:80]}  |  {txt.strip()[:50]}")
except Exception as e:
    print("ERR:", e)

# UPenn EE: 从 seas.upenn.edu/graduate/electrical-engineering/ 找具体项目页
print("\n=== UPenn seas.upenn.edu/graduate/electrical-engineering/ ===")
try:
    req = urllib.request.Request("https://seas.upenn.edu/graduate/electrical-engineering/", headers={"User-Agent": "Mozilla/5.0"})
    html = urllib.request.urlopen(req, timeout=15, context=SCTX).read().decode("utf-8", errors="ignore")
    print("size:", len(html))
    links = re.findall(r'href="([^"]*(?:electrical|graduate|masters|mse|ee)[^"]*)"[^>]*>([^<]{2,60})<', html, re.I)
    for href, txt in links[:25]:
        if "http" in href or href.startswith("/"):
            print(f"  {href[:90]}  |  {txt.strip()[:50]}")
except Exception as e:
    print("ERR:", e)

# JHU e-catalogue 全日制文理项目索引
print("\n=== JHU e-catalogue arts-sciences ===")
try:
    req = urllib.request.Request("https://e-catalogue.jhu.edu/arts-sciences/", headers={"User-Agent": "Mozilla/5.0"})
    html = urllib.request.urlopen(req, timeout=15, context=SCTX).read().decode("utf-8", errors="ignore")
    print("size:", len(html))
    links = re.findall(r'href="(/arts-sciences/[^"]*programs/[^"]*)"[^>]*>([^<]{2,60})<', html, re.I)
    for href, txt in links[:30]:
        print(f"  {href[:80]}  |  {txt.strip()[:50]}")
except Exception as e:
    print("ERR:", e)
