fix: 본문 블록에 widget 클래스를 쓰는 사이트에서 근거 본문이 비는 문제를 고친다

Elementor 계열 페이지 빌더는 본문 블록마다 widget 클래스를 달아, 사이드바 위젯용 노이즈 규칙이 본문 전체를 지웠다(모프로의원 남성 모발이식 페이지 48,239자 → 0자).
노이즈 제거 뒤 본문이 80% 넘게 사라지면 widget 규칙만 빼고 다시 추출하고, 이때도 푸터 위젯(사업자 정보·저작권 줄)은 지운다.
회귀 비교(12쪽 표본): 뷰성형외과 변화 없음, 오라클피부과 0자였던 6쪽이 본문을 얻음.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Haewon KamandClaude Opus 5.5 committed 2026-10-12 08:58:54 +09:00
1 parent a97a6391d0
commit 5893461fa9
1 file changed
+10 -2
+10 -2
View File
@@ -205,7 +205,11 @@ function walk(el, items) {
}
}
function extract(html, url) {
// 페이지 빌더(Elementor 등)는 본문 블록마다 "widget" 클래스를 단다(2026-10-08 모프로의원: 노이즈 제거로 본문 48,239자 → 0자).
// 노이즈 제거 뒤 본문이 80% 넘게 사라지면 widget 규칙만 빼고 다시 추출한다. 사이드바 위젯 사이트는 이 조건에 걸리지 않는다.
const NOISE_SELECTORS_KEEP_WIDGETS = NOISE_SELECTORS.split(',').filter((s) => s !== '[class*="widget"]').join(',');
function extract(html, url, keepWidgets = false) {
const root = parse(html, { blockTextElements: { script: true, style: true, noscript: true, pre: true } });
const title = clean(root.querySelector('title')?.text ?? '');
const metaDesc = root.querySelector('meta[name="description"]')?.getAttribute('content') ?? '';
@@ -219,7 +223,11 @@ function extract(html, url) {
if (!main) { const found = MAIN_SELECTORS.map((sel) => body.querySelector(sel)).filter(Boolean); if (found.length) main = found.sort((a, b) => clean(b.text).length - clean(a.text).length)[0]; }
main = main ?? body;
const mainSelector = main === body ? 'body' : MAIN_SELECTORS.find((s) => body.querySelector(s) === main);
main.querySelectorAll(NOISE_SELECTORS).forEach((e) => e.remove());
const beforeNoise = clean(main.text).length;
main.querySelectorAll(keepWidgets ? NOISE_SELECTORS_KEEP_WIDGETS : NOISE_SELECTORS).forEach((e) => e.remove());
if (!keepWidgets && beforeNoise > 100 && clean(main.text).length < beforeNoise * 0.2) return extract(html, url, true);
// 다시 추출할 때도 푸터 위젯(사업자 정보·저작권 줄만 담은 짧은 블록)은 지운다. 이미지뿐인 페이지에서 푸터가 본문으로 잡히는 것을 막는다
if (keepWidgets) main.querySelectorAll('[class*="widget"]').filter((e) => clean(e.text).length < 600 && /copyright|사업자\s*등록\s*번호/i.test(e.text)).forEach((e) => e.remove());
const items = []; walk(main, items);
const images = main.querySelectorAll('img').map((i) => ({ src: normalize(i.getAttribute('data-src') || i.getAttribute('src') || '', url), alt: clean(i.getAttribute('alt') ?? '') })).filter((i) => i.src && !/\.(svg|gif)$/i.test(i.src) && !/icon|logo|btn|button|arrow|blank|spacer|sns|share|1x1/i.test(i.src));
const links = [...new Set(main.querySelectorAll('a[href]').map((a) => normalize(a.getAttribute('href'), url)).filter(Boolean))];