# -*- 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")

html = open(os.path.join(BASE,"_hds_eas.html"),encoding="utf-8").read()
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()
i = text.find("Engineering and Applied Sciences", 1200)
print("=== EAS 4200 之后 ===")
print(text[i+4200:i+7000])

for u in ["https://gsas.harvard.edu/apply","https://gsas.harvard.edu/apply/admissions-requirements","https://gsas.harvard.edu/admissions"]:
    try:
        st,h=fetch(u)
        b=re.sub(r"<script.*?</script>"," ",h,flags=re.S); b=re.sub(r"<style.*?</style>"," ",b,flags=re.S)
        t=re.sub(r"\s+"," ",re.sub(r"<[^>]+>"," ",b)).strip()
        print(f"\n=== {st} len={len(h)} text={len(t)} {u}")
        for k in ["TOEFL","IELTS","Duolingo","English","recommendation","transcript","statement","resume","CV","application fee","fee","credits","resident"]:
            if k in t:
                j=t.find(k); print(f"  [{k}] …{t[max(0,j-50):j+110]}…")
    except Exception as e:
        print("ERR",u,repr(e)[:100])
