3 Commits

Author SHA1 Message Date
Jayant Sharma
1412926f5c [fix] braveapi: strip HTML tags and filter favicon thumbnails (#6381) 2026-07-08 21:19:11 +02:00
Bnyro
3b573e0f89 [fix] heexy: use cookies for cacheft token
Heexy now passes the cacheft token via cookies and no
longer via HTTP headers.

Hence, the engine is broken without that change.
2026-07-08 21:01:11 +02:00
Bnyro
da6a230413 [fix] autocomplete: google autocompleter crashes
`engines` only contains active engines. Since `google` was set to
inactive, it's no longer part of the , making the engine crash.

With this workaround, we directly load the engine traits from the data
dictionary instead of going the intermediate step with the Google engine.
2026-07-08 20:48:15 +02:00
3 changed files with 20 additions and 10 deletions

View File

@@ -21,6 +21,8 @@ from searx.engines import (
from searx.network import get as http_get, post as http_post from searx.network import get as http_get, post as http_post
from searx.exceptions import SearxEngineResponseException from searx.exceptions import SearxEngineResponseException
from searx.utils import extr, gen_useragent from searx.utils import extr, gen_useragent
from searx.data import ENGINE_TRAITS
from searx.enginelib.traits import EngineTraits
if t.TYPE_CHECKING: if t.TYPE_CHECKING:
from searx.extended_types import SXNG_Response from searx.extended_types import SXNG_Response
@@ -133,7 +135,9 @@ def google_complete(query: str, sxng_locale: str) -> list[str]:
""" """
google_info: dict[str, t.Any] = google.get_google_info({'searxng_locale': sxng_locale}, engines['google'].traits) data = ENGINE_TRAITS.get("google") or {}
traits = EngineTraits(**data)
google_info: dict[str, t.Any] = google.get_google_info({'searxng_locale': sxng_locale}, traits)
url = 'https://{subdomain}/complete/search?{args}' url = 'https://{subdomain}/complete/search?{args}'
args = urlencode( args = urlencode(
{ {

View File

@@ -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,
), ),
) )

View File

@@ -13,13 +13,12 @@ It seems to use Bing internally, as the image thumbnails are loaded from Bing.
from urllib.parse import urlencode from urllib.parse import urlencode
import typing as t import typing as t
from lxml import html
from searx.enginelib import EngineCache from searx.enginelib import EngineCache
from searx.network import get from searx.network import get
from searx.exceptions import SearxEngineAPIException, SearxEngineAccessDeniedException from searx.exceptions import SearxEngineAPIException, SearxEngineAccessDeniedException
from searx.result_types import EngineResults from searx.result_types import EngineResults
from searx.utils import eval_xpath, extract_text, gen_useragent from searx.utils import gen_useragent
if t.TYPE_CHECKING: if t.TYPE_CHECKING:
from searx.extended_types import SXNG_Response from searx.extended_types import SXNG_Response
@@ -73,8 +72,7 @@ def _get_api_token(query: str) -> str:
if not resp.ok: if not resp.ok:
raise SearxEngineAPIException("failed to obtain request token: invalid response code") raise SearxEngineAPIException("failed to obtain request token: invalid response code")
doc = html.fromstring(resp.text) token = resp.cookies["cacheft"]
token = extract_text(eval_xpath(doc, "//html/@data-cacheft"))
if not token: if not token:
raise SearxEngineAPIException("failed to obtain request token: no token found") raise SearxEngineAPIException("failed to obtain request token: no token found")
@@ -92,8 +90,9 @@ def request(query: str, params: "OnlineParams") -> None:
args["lang"] = params["searxng_locale"].split("-")[0] args["lang"] = params["searxng_locale"].split("-")[0]
params["url"] = f"{api_url}/search/{heexy_categ}?{urlencode(args)}" params["url"] = f"{api_url}/search/{heexy_categ}?{urlencode(args)}"
params["headers"]["X-Data-Cacheft"] = _get_api_token(query)
params["headers"]["Origin"] = api_url params["headers"]["Origin"] = api_url
params["cookies"]["cacheft"] = _get_api_token(query)
def response(resp: "SXNG_Response"): def response(resp: "SXNG_Response"):