[fix] naver: update HTML parsing for redesigned Naver search results page

Naver redesigned their search results page, replacing the old CSS classes
(lst_total, link_tit, total_dsc_wrap, api_txt_lines) with a new layout
using fds-web-doc-root containers and sds-comps design system.

Updated parse_general():
- Result container: fds-web-doc-root + fds-web-normal-doc-root
- Title: sds-comps-text-type-headline1 span
- URL: first external http link (with try/except guard)
- Content: sds-comps-text-type-body1 span
- Thumbnail: profile-thumbnail img src
- Added guard: skip results without title or URL
This commit is contained in:
Sisyphus
2026-06-28 15:48:04 +09:00
committed by Bnyro
parent b084194c09
commit 28d3885764

View File

@@ -99,21 +99,33 @@ def parse_general(data):
dom = html.fromstring(data) dom = html.fromstring(data)
for item in eval_xpath_list(dom, "//ul[contains(@class, 'lst_total')]/li[contains(@class, 'bx')]"): for item in eval_xpath_list(dom, "//div[contains(@class, 'fds-web-normal-doc-root')]"):
thumbnail = None thumbnail = extract_text(
eval_xpath(
item,
".//div[contains(@class, 'sds-comps-image') and not(contains(@class, 'sds-comps-image-circle'))]/img/@src",
)
)
title = extract_text(eval_xpath(item, ".//span[contains(@class, 'sds-comps-text-type-headline1')]"))
url = None
try: try:
thumbnail = eval_xpath_getindex(item, ".//div[contains(@class, 'thumb_single')]//img/@data-lazysrc", 0) url = eval_xpath_getindex(
item, ".//a[starts-with(@href, 'http') and not(contains(@href, 'keep.naver.com'))]/@href", 0
)
except (ValueError, TypeError, SearxEngineXPathException): except (ValueError, TypeError, SearxEngineXPathException):
pass pass
content = extract_text(eval_xpath(item, ".//span[contains(@class, 'sds-comps-text-type-body1')]"))
if title and url:
results.add( results.add(
MainResult( MainResult(
title=extract_text(eval_xpath(item, ".//a[contains(@class, 'link_tit')]")), title=title,
url=eval_xpath_getindex(item, ".//a[contains(@class, 'link_tit')]/@href", 0), url=url,
content=extract_text( content=content or "",
eval_xpath(item, ".//div[contains(@class, 'total_dsc_wrap')]//a[contains(@class, 'api_txt_lines')]") thumbnail=thumbnail or "",
),
thumbnail=thumbnail,
) )
) )
@@ -173,7 +185,7 @@ def parse_news(data):
title=title, title=title,
url=url, url=url,
content=content, content=content,
thumbnail=thumbnail, thumbnail=thumbnail or "",
) )
) )
@@ -196,7 +208,7 @@ def parse_videos(data):
length = None length = None
try: try:
length = parse_duration_string(extract_text(eval_xpath(item, ".//span[contains(@class, 'time')]"))) length = parse_duration_string(extract_text(eval_xpath(item, ".//span[contains(@class, 'time')]")) or "")
except (ValueError, TypeError): except (ValueError, TypeError):
pass pass