# -*- coding: utf-8 -*-
import io, sys, re, html
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
BASE = r"D:\work buddy\2026-11-05-14-15-52"
h = open(BASE + r"_duke_econ.html", encoding="utf-8").read()

# 站内/系站链接
links = sorted(set(re.findall(r'href="([^"]+)"', h)))
print("=== 含 econ / admissions / tuition / financial / curriculum 的链接 ===")
for l in links:
    if re.search(r"econ|admiss|tuition|financial|curricul|degree|graduate|appl", l, re.I):
        print(" ", l)

body = re.sub(r"<script.*?</script>", " ", h, flags=re.S)
body = re.sub(r"<style.*?</style>", " ", body, flags=re.S)
body = html.unescape(re.sub(r"<[^>]+>", " ", body))
body = re.sub(r"\s+", " ", body)

print("\n=== 关键词上下文 ===")
for kw in ["STEM", "credit", "tuition", "TOEFL", "IELTS", "Duolingo", "GRE", "GMAT",
           "scholarship", "assistantship", "curriculum", "semester", "writing sample", "video", "questionnaire", "waiver"]:
    for m in re.finditer(kw, body, re.I):
        a = max(0, m.start()-70); b = min(len(body), m.end()+90)
        print(f"[{kw}] ...{body[a:b]}...")
        break
