on master help sign in
[fix] google engine - div classes has been renamed in HTML reult

Since 1. October 2020 google has changed the 'class' attribute of the HTML result page. Fix the xpath expressions and ignore <div class="g" ../> sections which do not match to title's xpath expression. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commit8162d7aff4a61801615d8044b71c7c477b2b2816 authorMarkus Heiser <markus.heiser@darmarit.de> dateThu 1 Oct 2020, 09:44 (6 years ago) parentfd5fe36
1 file changed+11−6
searx/engines/google.py+11−6
searx/engines/google.py+11−6
@@ -116,12 +116,12 @@ g_section_with_header = './g-section-with-header'
116116# the title is a h3 tag relative to the result group
117117title_xpath = './/h3[1]'
118118
119−# in the result group there is <div class="r" ../> it's first child is a <a
120−# href=...> (on some results, the <a> is the first "descendant", not ""child")
121−href_xpath = './/div[@class="r"]//a/@href'
119+# in the result group there is <div class="yuRUbf" ../> it's first child is a <a
120+# href=...>
121+href_xpath = './/div[@class="yuRUbf"]//a/@href'
122122
123−# in the result group there is <div class="s" ../> containing he *content*
124−content_xpath = './/div[@class="s"]'
123+# in the result group there is <div class="IsZvec" ../> containing he *content*
124+content_xpath = './/div[@class="IsZvec"]'
125125
126126# Suggestions are links placed in a *card-section*, we extract only the text
127127# from the links not the links itself.
@@ -249,7 +249,12 @@ def response(resp):
249249 continue
250250
251251 try:
252− title = extract_text(eval_xpath(result, title_xpath)[0])
252+ title_tag = eval_xpath(result, title_xpath)
253+ if not title_tag:
254+ # this not one of the common google results *section*
255+ logger.debug('ingoring <div class="g" ../> section: missing title')
256+ continue
257+ title = extract_text(title_tag[0])
253258 url = eval_xpath(result, href_xpath)[0]
254259 content = extract_text_from_dom(result, content_xpath)
255260 results.append({