import os
import re
import sys
sys.stdout.reconfigure(encoding='utf-8')
def extract_content(html):
# 1. titleの抽出
title_match = re.search(r'
(.*?)', html, re.DOTALL | re.IGNORECASE)
title = title_match.group(1).strip() if title_match else "FF14 攻略Wiki"
# 2. meta descriptionの抽出
desc_match = re.search(r'\n' if desc_match else ""
# 3. メインコンテンツの抽出
# パターンA: ...
main_match = re.search(r'(.*?)', html, re.DOTALL | re.IGNORECASE)
if main_match:
return title, meta_desc, main_match.group(1).strip(), "main#wiki-main"
# パターンB: (.*?)
main_match = re.search(r'(.*?)', html, re.DOTALL | re.IGNORECASE)
if main_match:
return title, meta_desc, main_match.group(1).strip(), "main.wiki-main"
# パターンC: (.*?)
main_match = re.search(r'(.*?)', html, re.DOTALL | re.IGNORECASE)
if main_match:
return title, meta_desc, main_match.group(1).strip(), "main#wiki-main-container"
# パターンD: (.*?)
main_match = re.search(r'(.*?)', html, re.DOTALL | re.IGNORECASE)
if main_match:
content = main_match.group(1).strip()
# 空のパンくず除外
content = re.sub(r'\s*
', '', content)
return title, meta_desc, content.strip(), "main#wiki-content"
# パターンE: (.*?)
\s*
main_match = re.search(r'(.*?)
\s*', html, re.DOTALL | re.IGNORECASE)
if main_match:
return title, meta_desc, main_match.group(1).strip(), "div.wiki-content"
return title, meta_desc, None, "UNKNOWN"
test_files = [
'trials/ultima_weapon.html',
'trials/extreme_hades.html',
'trials/garuda.html',
'dungeons/amdapor_keep_hard.html',
'dungeons/aurum_vale.html',
'dungeons/index.html',
'raids/syrcus_tower.html',
'raids/index.html'
]
for p in test_files:
with open(p, 'r', encoding='utf-8', errors='ignore') as fp:
html = fp.read()
t, d, c, pattern = extract_content(html)
print(f"File: {p:<35} | Pattern: {pattern:<25} | Title: {t[:30]} | Content Length: {len(c) if c else 0}")