mirror of
https://github.com/searxng/searxng.git
synced 2026-07-17 21:41:24 +00:00
Compare commits
3 Commits
f69b22c45c
...
1412926f5c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1412926f5c | ||
|
|
3b573e0f89 | ||
|
|
da6a230413 |
@@ -21,6 +21,8 @@ from searx.engines import (
|
||||
from searx.network import get as http_get, post as http_post
|
||||
from searx.exceptions import SearxEngineResponseException
|
||||
from searx.utils import extr, gen_useragent
|
||||
from searx.data import ENGINE_TRAITS
|
||||
from searx.enginelib.traits import EngineTraits
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
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}'
|
||||
args = urlencode(
|
||||
{
|
||||
|
||||
@@ -31,6 +31,7 @@ from dateutil import parser
|
||||
|
||||
from searx.exceptions import SearxEngineAPIException
|
||||
from searx.result_types import EngineResults
|
||||
from searx.utils import html_to_text
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from searx.extended_types import SXNG_Response
|
||||
@@ -75,6 +76,7 @@ def request(query: str, params: "OnlineParams") -> None:
|
||||
"q": query,
|
||||
"count": results_per_page,
|
||||
"offset": (params["pageno"] - 1) * results_per_page,
|
||||
"text_decorations": False,
|
||||
}
|
||||
|
||||
# Apply time filter if specified
|
||||
@@ -112,14 +114,19 @@ def response(resp: "SXNG_Response") -> EngineResults:
|
||||
res = EngineResults()
|
||||
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.types.MainResult(
|
||||
url=result["url"],
|
||||
title=result["title"],
|
||||
content=result.get("description", ""),
|
||||
title=html_to_text(result["title"]),
|
||||
content=html_to_text(result.get("description", "")),
|
||||
publishedDate=_extract_published_date(result.get("age")),
|
||||
thumbnail=result.get("thumbnail", {}).get("src"),
|
||||
thumbnail=thumbnail,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -13,13 +13,12 @@ It seems to use Bing internally, as the image thumbnails are loaded from Bing.
|
||||
from urllib.parse import urlencode
|
||||
|
||||
import typing as t
|
||||
from lxml import html
|
||||
|
||||
from searx.enginelib import EngineCache
|
||||
from searx.network import get
|
||||
from searx.exceptions import SearxEngineAPIException, SearxEngineAccessDeniedException
|
||||
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:
|
||||
from searx.extended_types import SXNG_Response
|
||||
@@ -73,8 +72,7 @@ def _get_api_token(query: str) -> str:
|
||||
if not resp.ok:
|
||||
raise SearxEngineAPIException("failed to obtain request token: invalid response code")
|
||||
|
||||
doc = html.fromstring(resp.text)
|
||||
token = extract_text(eval_xpath(doc, "//html/@data-cacheft"))
|
||||
token = resp.cookies["cacheft"]
|
||||
if not token:
|
||||
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]
|
||||
|
||||
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["cookies"]["cacheft"] = _get_api_token(query)
|
||||
|
||||
|
||||
def response(resp: "SXNG_Response"):
|
||||
|
||||
Reference in New Issue
Block a user