summaryrefslogtreecommitdiff
path: root/searx/engines/xpath.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarIT.de>2022-09-04 09:14:34 +0200
committerGitHub <noreply@github.com>2022-09-04 09:14:34 +0200
commit9ab843813229476744b4206a26dedb26b36c1782 (patch)
tree2d2518e194b905407c396d70b2f8f40864869ec8 /searx/engines/xpath.py
parent8e9fb0b43582aa41123dd0ff64ff5088ce0ec4c9 (diff)
parentdd0887be186d208846cdc7c3df13dde020dfa957 (diff)
Merge pull request #1681 from return42/fix-woxikon
[fix] engine woxikon.de - don't raise exception on empty result list
Diffstat (limited to 'searx/engines/xpath.py')
-rw-r--r--searx/engines/xpath.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/searx/engines/xpath.py b/searx/engines/xpath.py
index 705a5211d..f9528e92d 100644
--- a/searx/engines/xpath.py
+++ b/searx/engines/xpath.py
@@ -22,6 +22,7 @@ from urllib.parse import urlencode
from lxml import html
from searx.utils import extract_text, extract_url, eval_xpath, eval_xpath_list
+from searx.network import raise_for_httperror
search_url = None
"""
@@ -61,6 +62,14 @@ lang_all = 'en'
selected.
'''
+no_result_for_http_status = []
+'''Return empty result for these HTTP status codes instead of throwing an error.
+
+.. code:: yaml
+
+ no_result_for_http_status: []
+'''
+
soft_max_redirects = 0
'''Maximum redirects, soft limit. Record an error but don't stop the engine'''
@@ -177,11 +186,18 @@ def request(query, params):
params['url'] = search_url.format(**fargs)
params['soft_max_redirects'] = soft_max_redirects
+ params['raise_for_httperror'] = False
+
return params
-def response(resp):
+def response(resp): # pylint: disable=too-many-branches
'''Scrap *results* from the response (see :ref:`engine results`).'''
+ if no_result_for_http_status and resp.status_code in no_result_for_http_status:
+ return []
+
+ raise_for_httperror(resp)
+
results = []
dom = html.fromstring(resp.text)
is_onion = 'onions' in categories