summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2021-01-26 12:51:54 +0100
committerMarkus Heiser <markus.heiser@darmarit.de>2021-01-28 10:08:50 +0100
commit7f505bdc6fad1f744992f663a29ea57c0f8fbc40 (patch)
tree32cc3d6fcdeb71ced8aa8fb95eb9a1225ee6ede5 /searx
parente436287385d448eb54f80398bc181598333cf6be (diff)
[fix] google: avoid unnecessary SearxEngineXPathException errors
Avoid SearxEngineXPathException errors when parsing non valid results:: .//div[@class="yuRUbf"]//a/@href index 0 not found Traceback (most recent call last): File "./searx/engines/google.py", line 274, in response url = eval_xpath_getindex(result, href_xpath, 0) File "./searx/searx/utils.py", line 608, in eval_xpath_getindex raise SearxEngineXPathException(xpath_spec, 'index ' + str(index) + ' not found') searx.exceptions.SearxEngineXPathException: .//div[@class="yuRUbf"]//a/@href index 0 not found Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx')
-rw-r--r--searx/engines/google.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/searx/engines/google.py b/searx/engines/google.py
index 979253ec5..138c90411 100644
--- a/searx/engines/google.py
+++ b/searx/engines/google.py
@@ -271,7 +271,9 @@ def response(resp):
logger.debug('ingoring <div class="g" ../> section: missing title')
continue
title = extract_text(title_tag)
- url = eval_xpath_getindex(result, href_xpath, 0)
+ url = eval_xpath_getindex(result, href_xpath, 0, None)
+ if url is None:
+ continue
content = extract_text(eval_xpath_getindex(result, content_xpath, 0, default=None), allow_none=True)
results.append({
'url': url,