# -*- coding: utf-8 -*-
import io, sys, re, ssl, urllib.request, os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
BASE = 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, timeout=18):
    req = urllib.request.Request(url, headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/120 Safari/537.36"})
    with urllib.request.urlopen(req, timeout=timeout, context=ctx) as r:
        raw=r.read(); enc=r.headers.get_content_charset() or "utf-8"
        return r.status, raw.decode(enc, errors="replace")

cands = [
 "https://gsas.harvard.edu/program/engineering-and-applied-sciences",
 "https://gsas.harvard.edu/admissions/applying-degree-programs",
 "https://gsas.harvard.edu/admissions/international-applicants",
 "https://gsas.harvard.edu/admissions/cost-attendance",
 "https://gsas.harvard.edu/financial-support",
 "https://seas.harvard.edu/data-science",
 "https://www.seas.harvard.edu/academics/data-science",
 "https://datascience.harvard.edu/",
]
for u in cands:
    try:
        st, html = fetch(u)
        body = re.sub(r"<script.*?</script>"," ",html,flags=re.S)
        body = re.sub(r"<style.*?</style>"," ",body,flags=re.S)
        text = re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",body)).strip()
        print(f"=== {st} len={len(html)} text={len(text)} {u}")
        kw = [k for k in ["TOEFL","IELTS","Duolingo","tuition","Tuition","credit","Credits","residency","GPA","prerequisite","recommendation","transcript","statement","application fee","deadline","Dec"] if k in text]
        print("   kw:", kw)
        print("   正文片段:", text[:240])
    except Exception as e:
        print("ERR", u, repr(e)[:120])
