diff options
| author | Bnyro <bnyro@tutanota.com> | 2026-09-02 13:28:52 +0200 |
|---|---|---|
| committer | Bnyro <bnyro@tutanota.com> | 2026-09-05 19:11:49 +0200 |
| commit | ccffbfc1649e4fefb4f87733407af381b629a145 (patch) | |
| tree | 6b3d6493255824ed7400618f7b0af08475988c92 | |
| parent | 242dc6e3988e47b44601e300e0ea65bac110cb7d (diff) | |
[fix] searchzee: bypass botblocking
requires https://github.com/searxng/searxng/pull/6620
| -rw-r--r-- | searx/engines/searchzee.py | 34 |
1 files changed, 4 insertions, 30 deletions
diff --git a/searx/engines/searchzee.py b/searx/engines/searchzee.py index 00cc51fb5..7573005e8 100644 --- a/searx/engines/searchzee.py +++ b/searx/engines/searchzee.py @@ -4,13 +4,11 @@ independent search infrastructure.""" import typing as t from urllib.parse import urlencode +import uuid -from searx.exceptions import SearxEngineAPIException from searx.extended_types import SXNG_Response -from searx.network import get from searx.result_types import EngineResults -from searx.utils import extr, html_to_text -from searx.enginelib import EngineCache +from searx.utils import html_to_text if t.TYPE_CHECKING: from searx.search.processors import OnlineParams @@ -34,43 +32,19 @@ SearchzeeCategType = t.Literal["web", "news"] searchzee_categ: SearchzeeCategType = None # type: ignore[reportAssignmentType] -CACHE: EngineCache -"""Cache for storing the scraped API Token.""" - base_url = "https://searchzee.com" # only supports for news time_range_map = {"day": "pd", "week": "pw", "month": "pm", "year": "py"} -def setup(engine_settings: dict[str, t.Any]) -> bool: +def setup(_: dict[str, t.Any]): if searchzee_categ not in t.get_args(SearchzeeCategType): raise ValueError("invalid category: %s" % searchzee_categ) - global CACHE # pylint: disable=global-statement - CACHE = EngineCache(engine_settings["name"]) # type: ignore[reportAny] - return True - - -def _obtain_api_token() -> str: - token: str | None = CACHE.get("token") # type: ignore[reportAny] - if token: - return token - - token_resp = get( - f"{base_url}/app.js", - ) - if not token_resp.ok: - raise SearxEngineAPIException("failed to obtain api key") - - token = extr(token_resp.text, "const SEARCHZEE_API_TOKEN = \"", "\";") - CACHE.set("token", token, expire=3600) - - return token - def request(query: str, params: "OnlineParams"): - params["headers"]["X-SearchZee-Token"] = _obtain_api_token() + params["cookies"]["szs"] = str(uuid.uuid4()) args = {"q": query, "type": searchzee_categ, "offset": params["pageno"] - 1} if params["time_range"]: |
