From 155333f62568e942cf27de83e4bcd037d4010224 Mon Sep 17 00:00:00 2001 From: Allen <64094914+allendema@users.noreply.github.com> Date: Sat, 16 Apr 2022 17:42:04 +0200 Subject: [PATCH 1/3] [enh] Allow passing headers/cookies from settings.yml Example: - engine: xpath - search_url: example.org - headers: {'example_header': 'example_header'} - cookies: {'safesearch': 'off'} --- searx/engines/xpath.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/searx/engines/xpath.py b/searx/engines/xpath.py index 2737bf94a..7a41d9475 100644 --- a/searx/engines/xpath.py +++ b/searx/engines/xpath.py @@ -85,6 +85,11 @@ suggestion_xpath = '' cached_xpath = '' cached_url = '' +cookies = {} +headers = {} +'''Some engines might offer different result based on cookies or headers. +Possible use-case: To set safesearch cookie or header to moderate.''' + paging = False '''Engine supports paging [True or False].''' @@ -166,6 +171,9 @@ def request(query, params): 'safe_search': safe_search, } + params['cookies'] = cookies + params['headers'] = headers + params['url'] = search_url.format(**fargs) params['soft_max_redirects'] = soft_max_redirects From 67fb6fba84d189bc099fc90b1df71db232689f53 Mon Sep 17 00:00:00 2001 From: Allen <64094914+allendema@users.noreply.github.com> Date: Sun, 17 Apr 2022 10:42:25 +0200 Subject: [PATCH 2/3] [lint] Remove whitespace From GH GUI --- searx/engines/xpath.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/searx/engines/xpath.py b/searx/engines/xpath.py index 7a41d9475..a34ed38b2 100644 --- a/searx/engines/xpath.py +++ b/searx/engines/xpath.py @@ -173,7 +173,7 @@ def request(query, params): params['cookies'] = cookies params['headers'] = headers - + params['url'] = search_url.format(**fargs) params['soft_max_redirects'] = soft_max_redirects From dae8a080898d0dd2d7a8924123b159daece0edd6 Mon Sep 17 00:00:00 2001 From: Allen <64094914+allendema@users.noreply.github.com> Date: Sun, 17 Apr 2022 11:29:23 +0200 Subject: [PATCH 3/3] [fix[ Update only cookies/headers --- searx/engines/xpath.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/searx/engines/xpath.py b/searx/engines/xpath.py index a34ed38b2..705a5211d 100644 --- a/searx/engines/xpath.py +++ b/searx/engines/xpath.py @@ -171,8 +171,8 @@ def request(query, params): 'safe_search': safe_search, } - params['cookies'] = cookies - params['headers'] = headers + params['cookies'].update(cookies) + params['headers'].update(headers) params['url'] = search_url.format(**fargs) params['soft_max_redirects'] = soft_max_redirects