[fix] ddg engine: IndexError exception is raised on empty contend (#4843)

Sometimes (e.g. when ddg does not have a result item) there is no content and
the engine will fail with an IndexError:

  * Error: IndexError
  * Percentage: 10
  * Parameters: `()`
  * File name: `searx/engines/duckduckgo.py:375`
  * Function: `response`
  * Code: `item["content"] = extract_text(eval_xpath(div_result, './/a[contains(@class, "result__snippet")]')[0])`

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2025-05-23 14:55:22 +02:00 committed by GitHub
parent 4fa7de8033
commit 1ef5c03962
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -372,8 +372,9 @@ def response(resp) -> EngineResults:
continue
item["title"] = extract_text(title)
item["url"] = eval_xpath(div_result, './/h2/a/@href')[0]
item["content"] = extract_text(eval_xpath(div_result, './/a[contains(@class, "result__snippet")]')[0])
item["content"] = extract_text(
eval_xpath_getindex(div_result, './/a[contains(@class, "result__snippet")]', 0, [])
)
results.append(item)
zero_click_info_xpath = '//div[@id="zero_click_abstract"]'