on master help sign in
[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 <markus.heiser@darmarit.de>

commit26c92d5f5014113e5a1acae9328dfc45bb7f6d20 authorMarkus Heiser <markus.heiser@darmarit.de> dateTue 18 Jan 2022, 11:05 (5 years ago) parenta2ec276
1 file changed+8−2
searx/engines/google.py+8−2
searx/engines/google.py+8−2
@@ -109,7 +109,8 @@ filter_mapping = {
109109# ------------------------
110110
111111# google results are grouped into <div class="g ..." ../>
112−results_xpath = '//div[contains(@class, "g")]'
112+results_xpath = '//div[@id="search"]//div[contains(@class, "g ")]'
113+results_xpath_mobile_ui = '//div[contains(@class, "g ")]'
113114
114115# google *sections* are no usual *results*, we ignore them
115116g_section_with_header = './g-section-with-header'
@@ -274,7 +275,12 @@ def response(resp):
274275 logger.error(e, exc_info=True)
275276
276277 # parse results
277− for result in eval_xpath_list(dom, results_xpath):
278+
279+ _results_xpath = results_xpath
280+ if use_mobile_ui:
281+ _results_xpath = results_xpath_mobile_ui
282+
283+ for result in eval_xpath_list(dom, _results_xpath):
278284
279285 # google *sections*
280286 if extract_text(eval_xpath(result, g_section_with_header)):