SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
[fix] engine zlibrary: handle seized domain
Markus Heiser39ffec87b7f8
diff --git a/searx/engines/zlibrary.py b/searx/engines/zlibrary.pyindex c29c9135c..0eed5f621 100644--- a/searx/engines/zlibrary.py+++ b/searx/engines/zlibrary.py@@ -43,6 +43,7 @@ from flask_babel import gettextfrom searx.utils import extract_text, eval_xpath, eval_xpath_listfrom searx.enginelib.traits import EngineTraitsfrom searx.data import ENGINE_TRAITS+from searx.exceptions import SearxExceptionif TYPE_CHECKING:import httpx@@ -108,13 +109,21 @@ def request(query: str, params: Dict[str, Any]) -> Dict[str, Any]:zlib_year_to=zlib_year_to,zlib_ext=zlib_ext,)+ params["verify"] = Falsereturn params+def domain_is_seized(dom):+ return bool(dom.xpath('//title') and "seized" in dom.xpath('//title')[0].text.lower())++def response(resp: httpx.Response) -> List[Dict[str, Any]]:results: List[Dict[str, Any]] = []dom = html.fromstring(resp.text)+ if domain_is_seized(dom):+ raise SearxException(f"zlibrary domain is seized: {base_url}")+for item in dom.xpath('//div[@id="searchResultBox"]//div[contains(@class, "resItemBox")]'):results.append(_parse_result(item))@@ -168,22 +177,30 @@ def _parse_result(item) -> Dict[str, Any]:def fetch_traits(engine_traits: EngineTraits) -> None:"""Fetch languages and other search arguments from zlibrary's search form."""- # pylint: disable=import-outside-toplevel+ # pylint: disable=import-outside-toplevel, too-many-branchesimport babelfrom searx.network import get # see https://github.com/searxng/searxng/issues/762from searx.locales import language_tag+ resp = get(base_url, verify=False)+ if not resp.ok: # type: ignore+ raise RuntimeError("Response from zlibrary's search page is not OK.")+ dom = html.fromstring(resp.text) # type: ignore++ if domain_is_seized(dom):+ print(f"ERROR: zlibrary domain is seized: {base_url}")+ # don't change anything, re-use the existing values+ engine_traits.all_locale = ENGINE_TRAITS["z-library"]["all_locale"]+ engine_traits.custom = ENGINE_TRAITS["z-library"]["custom"]+ engine_traits.languages = ENGINE_TRAITS["z-library"]["languages"]+ return+engine_traits.all_locale = ""engine_traits.custom["ext"] = []engine_traits.custom["year_from"] = []engine_traits.custom["year_to"] = []- resp = get(base_url)- if not resp.ok: # type: ignore- raise RuntimeError("Response from zlibrary's search page is not OK.")- dom = html.fromstring(resp.text) # type: ignore-for year in eval_xpath_list(dom, "//div[@id='advSearch-noJS']//select[@id='sf_yearFrom']/option"):engine_traits.custom["year_from"].append(year.get("value"))