mirror of
https://github.com/searxng/searxng.git
synced 2026-07-29 19:31:35 +00:00
[fix] braveapi: strip HTML tags and filter favicon thumbnails (#6381)
This commit is contained in:
@@ -31,6 +31,7 @@ from dateutil import parser
|
|||||||
|
|
||||||
from searx.exceptions import SearxEngineAPIException
|
from searx.exceptions import SearxEngineAPIException
|
||||||
from searx.result_types import EngineResults
|
from searx.result_types import EngineResults
|
||||||
|
from searx.utils import html_to_text
|
||||||
|
|
||||||
if t.TYPE_CHECKING:
|
if t.TYPE_CHECKING:
|
||||||
from searx.extended_types import SXNG_Response
|
from searx.extended_types import SXNG_Response
|
||||||
@@ -75,6 +76,7 @@ def request(query: str, params: "OnlineParams") -> None:
|
|||||||
"q": query,
|
"q": query,
|
||||||
"count": results_per_page,
|
"count": results_per_page,
|
||||||
"offset": (params["pageno"] - 1) * results_per_page,
|
"offset": (params["pageno"] - 1) * results_per_page,
|
||||||
|
"text_decorations": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Apply time filter if specified
|
# Apply time filter if specified
|
||||||
@@ -112,14 +114,19 @@ def response(resp: "SXNG_Response") -> EngineResults:
|
|||||||
res = EngineResults()
|
res = EngineResults()
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
|
|
||||||
for result in data.get("web", {}).get("results", []):
|
for result in (data.get("web") or {}).get("results", []):
|
||||||
|
thumbnail_obj = result.get("thumbnail")
|
||||||
|
thumbnail = ""
|
||||||
|
if thumbnail_obj and not thumbnail_obj.get("logo", False):
|
||||||
|
thumbnail = thumbnail_obj.get("src") or ""
|
||||||
|
|
||||||
res.add(
|
res.add(
|
||||||
res.types.MainResult(
|
res.types.MainResult(
|
||||||
url=result["url"],
|
url=result["url"],
|
||||||
title=result["title"],
|
title=html_to_text(result["title"]),
|
||||||
content=result.get("description", ""),
|
content=html_to_text(result.get("description", "")),
|
||||||
publishedDate=_extract_published_date(result.get("age")),
|
publishedDate=_extract_published_date(result.get("age")),
|
||||||
thumbnail=result.get("thumbnail", {}).get("src"),
|
thumbnail=thumbnail,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user