on master help sign in
[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>

commit7f505bdc6fad1f744992f663a29ea57c0f8fbc40 authorMarkus Heiser <markus.heiser@darmarit.de> dateTue 26 Jan 2021, 12:51 (6 years ago) parente436287
1 file changed+3−1
searx/engines/google.py+3−1
searx/engines/google.py+3−1
@@ -271,7 +271,9 @@ def response(resp):
271271 logger.debug('ingoring <div class="g" ../> section: missing title')
272272 continue
273273 title = extract_text(title_tag)
274− url = eval_xpath_getindex(result, href_xpath, 0)
274+ url = eval_xpath_getindex(result, href_xpath, 0, None)
275+ if url is None:
276+ continue
275277 content = extract_text(eval_xpath_getindex(result, content_xpath, 0, default=None), allow_none=True)
276278 results.append({
277279 'url': url,