summaryrefslogtreecommitdiff
path: root/searx/engines/xpath.py
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2024-11-27 14:13:23 +0100
committerBnyro <bnyro@tutanota.com>2024-11-28 09:53:21 +0100
commit0ca2520115ecbdab40c746ce03d3331b5c21886d (patch)
tree930ac3a07b4f238b2b68a1417bd2c2625491a5b1 /searx/engines/xpath.py
parent5a9c1c6b5bc1963482e9c8142dffe8aebaed82b8 (diff)
downloadsearxng-0ca2520115ecbdab40c746ce03d3331b5c21886d.tar.gz
searxng-0ca2520115ecbdab40c746ce03d3331b5c21886d.zip
[feat] json/xpath engine: config option for method and body
Diffstat (limited to 'searx/engines/xpath.py')
-rw-r--r--searx/engines/xpath.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/searx/engines/xpath.py b/searx/engines/xpath.py
index 558531880..97c84bd09 100644
--- a/searx/engines/xpath.py
+++ b/searx/engines/xpath.py
@@ -12,6 +12,8 @@ Request:
- :py:obj:`search_url`
- :py:obj:`lang_all`
- :py:obj:`soft_max_redirects`
+- :py:obj:`method`
+- :py:obj:`request_body`
- :py:obj:`cookies`
- :py:obj:`headers`
@@ -151,6 +153,16 @@ headers = {}
'''Some engines might offer different result based headers. Possible use-case:
To set header to moderate.'''
+method = 'GET'
+'''Some engines might require to do POST requests for search.'''
+
+request_body = ''
+'''The body of the request. This can only be used if different :py:obj:`method`
+is set, e.g. ``POST``. For formatting see the documentation of :py:obj:`search_url`::
+
+ search={query}&page={pageno}{time_range}{safe_search}
+'''
+
paging = False
'''Engine supports paging [True or False].'''
@@ -236,8 +248,14 @@ def request(query, params):
params['headers'].update(headers)
params['url'] = search_url.format(**fargs)
- params['soft_max_redirects'] = soft_max_redirects
+ params['method'] = method
+
+ if request_body:
+ # don't url-encode the query if it's in the request body
+ fargs['query'] = query
+ params['data'] = request_body.format(**fargs)
+ params['soft_max_redirects'] = soft_max_redirects
params['raise_for_httperror'] = False
return params