summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2025-05-28 11:36:37 +0200
committerBnyro <bnyro@tutanota.com>2025-05-28 12:53:45 +0200
commit2288f07d621d67d6b39f0d0073cdcc951ec22726 (patch)
treea9aece00a435dbc60a330ed7e17bb69db0b30250
parent20b40351b9e36dffc06b44dfaf3c4846b569d63e (diff)
[fix] presearch: reuse response cookies from token extraction
Why? - presearch requires the response cookies of the first request to be sent within the second request - otherwise we miss auth information and the engine doesn't work Related: - https://github.com/searxng/searxng/pull/4858 - closes https://github.com/searxng/searxng/issues/4854 Co-authored-by: Aadniz <8147434+Aadniz@users.noreply.github.com>
-rw-r--r--searx/engines/presearch.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/searx/engines/presearch.py b/searx/engines/presearch.py
index 1093b5cff..36b754f87 100644
--- a/searx/engines/presearch.py
+++ b/searx/engines/presearch.py
@@ -137,19 +137,20 @@ def _get_request_id(query, params):
if l.territory:
headers['Accept-Language'] = f"{l.language}-{l.territory},{l.language};" "q=0.9,*;" "q=0.5"
- resp_text = get(url, headers=headers).text # type: ignore
+ resp = get(url, headers=headers)
- for line in resp_text.split("\n"):
+ for line in resp.text.split("\n"):
if "window.searchId = " in line:
- return line.split("= ")[1][:-1].replace('"', "")
+ return line.split("= ")[1][:-1].replace('"', ""), resp.cookies
- return None
+ raise RuntimeError("Couldn't find any request id for presearch")
def request(query, params):
- request_id = _get_request_id(query, params)
+ request_id, cookies = _get_request_id(query, params)
params["headers"]["Accept"] = "application/json"
params["url"] = f"{base_url}/results?id={request_id}"
+ params["cookies"] = cookies
return params