mirror of
https://github.com/searxng/searxng.git
synced 2026-07-17 21:41:24 +00:00
[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:
@@ -99,23 +99,35 @@ 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
|
||||||
|
|
||||||
results.add(
|
content = extract_text(eval_xpath(item, ".//span[contains(@class, 'sds-comps-text-type-body1')]"))
|
||||||
MainResult(
|
|
||||||
title=extract_text(eval_xpath(item, ".//a[contains(@class, 'link_tit')]")),
|
if title and url:
|
||||||
url=eval_xpath_getindex(item, ".//a[contains(@class, 'link_tit')]/@href", 0),
|
results.add(
|
||||||
content=extract_text(
|
MainResult(
|
||||||
eval_xpath(item, ".//div[contains(@class, 'total_dsc_wrap')]//a[contains(@class, 'api_txt_lines')]")
|
title=title,
|
||||||
),
|
url=url,
|
||||||
thumbnail=thumbnail,
|
content=content or "",
|
||||||
|
thumbnail=thumbnail or "",
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user