diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2022-01-18 11:05:45 +0100 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarit.de> | 2022-01-18 11:05:45 +0100 |
commit | f0102a95c96605cb0702a374f084f82074698cf2 (patch) | |
tree | f8224792f7ff92e1502385ca79ba6af2017105de /searx/engines/google.py | |
parent | b972df255a76e043522c9e4f44cbbcaa6b34df41 (diff) | |
download | searxng-f0102a95c96605cb0702a374f084f82074698cf2.tar.gz searxng-f0102a95c96605cb0702a374f084f82074698cf2.zip |
[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>
Diffstat (limited to 'searx/engines/google.py')
-rw-r--r-- | searx/engines/google.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/searx/engines/google.py b/searx/engines/google.py index 5ee00cca3..b681da17c 100644 --- a/searx/engines/google.py +++ b/searx/engines/google.py @@ -112,7 +112,8 @@ filter_mapping = {0: 'off', 1: 'medium', 2: 'high'} # ------------------------ # google results are grouped into <div class="g ..." ../> -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' @@ -336,7 +337,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)): |