import json, re

# 读取5个候选详情页占位文件
files = [
    'details/ucsd-computational-science-mathematics-and-engineering-ms.html',
    'details/ucsd-computational-social-science-ms.html',
    'details/ucsd-computer-science-and-engineering-advanced-manufacturing-ms.html',
    'details/ucsd-data-science-and-engineering-ms.html',
    'details/ucla-master-of-applied-geospatial-information-systems-and-technologies-ms.html',
]

for f in files:
    print(f'=== {f} ===')
    try:
        with open(f, 'r', encoding='utf-8') as fh:
            content = fh.read()
        print(f'文件大小: {len(content)} 字符')
        # 提取关键信息
        title = re.search(r'<title>(.*?)</title>', content)
        if title:
            print(f'标题: {title.group(1)}')
        # 提取所有文本内容（去标签）
        text = re.sub(r'<[^>]+>', ' ', content)
        text = re.sub(r'\s+', ' ', text).strip()
        print(f'文本预览: {text[:500]}')
    except Exception as e:
        print(f'错误: {e}')
    print()
