From 26c92d5f5014113e5a1acae9328dfc45bb7f6d20 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 18 Jan 2022 11:05:45 +0100 Subject: [PATCH] [fix] google engine: remove adds and fix mobile_ui selector 1. Fix issue reported in comment [1] 2. Fix XPath selector for the response of google's mobile UI, reported in comment [2] [1] https://github.com/searxng/searxng/pull/777#issuecomment-1015121322 [2] https://github.com/searxng/searxng/pull/777#issuecomment-1015236238 Signed-off-by: Markus Heiser --- searx/engines/google.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/searx/engines/google.py b/searx/engines/google.py index 12db26c4..95fa7e2b 100644 --- a/searx/engines/google.py +++ b/searx/engines/google.py @@ -109,7 +109,8 @@ filter_mapping = { # ------------------------ # google results are grouped into
-results_xpath = '//div[contains(@class, "g")]' +results_xpath = '//div[@id="search"]//div[contains(@class, "g ")]' +results_xpath_mobile_ui = '//div[contains(@class, "g ")]' # google *sections* are no usual *results*, we ignore them g_section_with_header = './g-section-with-header' @@ -274,7 +275,12 @@ def response(resp): logger.error(e, exc_info=True) # parse results - for result in eval_xpath_list(dom, results_xpath): + + _results_xpath = results_xpath + if use_mobile_ui: + _results_xpath = results_xpath_mobile_ui + + for result in eval_xpath_list(dom, _results_xpath): # google *sections* if extract_text(eval_xpath(result, g_section_with_header)):