import ssl, io, sys, re, urllib.request, html as htmllib
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

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

u = "https://www.duffield.cornell.edu/mae/on-campus-meng-program-mechanical-engineering/"
req = urllib.request.Request(u, headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"})
r = urllib.request.urlopen(req, timeout=25, context=ctx)
raw = r.read().decode("utf-8", errors="replace")
open("_cornell_mech_raw.html", "w", encoding="utf-8").write(raw)

links = re.findall(r'href="([^"]+)"', raw)
for h in dict.fromkeys(links):
    if any(k in h.lower() for k in ["requirement", "admiss", "guide", "degree", "curriculum", "handbook", "tuition", "bursar", "english", "toefl", "gre", "apply"]):
        print(h)

# anchor ids
print("\n=== ids ===")
for m in re.finditer(r'id="([^"]+)"', raw):
    print(m.group(1))
