[fix] google images: @href index 0 not found

Sometimes there is no href in the `<a ..>` tag of a *link_node* [1].

[1] https://github.com/searxng/searxng/issues/532

Reported-by: @TheEssem
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2021-11-21 09:54:05 +01:00
parent 1c8b731791
commit 5b28c9109f
1 changed files with 4 additions and 1 deletions

View File

@ -172,7 +172,10 @@ def response(resp):
thumbnail_src = '' thumbnail_src = ''
link_node = eval_xpath_getindex(img_node, '../../../a[2]', 0) link_node = eval_xpath_getindex(img_node, '../../../a[2]', 0)
url = eval_xpath_getindex(link_node, '@href', 0) url = eval_xpath_getindex(link_node, '@href', 0, None)
if url is None:
logger.error("missing @href in node: %s", html.tostring(link_node))
continue
pub_nodes = eval_xpath(link_node, './div/div') pub_nodes = eval_xpath(link_node, './div/div')
pub_descr = img_alt pub_descr = img_alt