@@ -14,7 +14,7 @@ from lxml import html, etree
1414from searx.engines.xpath import extract_text, extract_url
1515from searx import logger
1616from searx.url_utils import urlencode, urlparse, parse_qsl
17−from searx.utils import match_language
17+from searx.utils import match_language, eval_xpath
1818
1919logger = logger.getChild('google engine')
2020
@@ -156,7 +156,7 @@ def parse_url(url_string, google_hostname):
156156
157157# returns extract_text on the first result selected by the xpath or None
158158def extract_text_from_dom(result, xpath):
159− r = result.xpath(xpath)
159+ r = eval_xpath(result, xpath)
160160 if len(r) > 0:
161161 return extract_text(r[0])
162162 return None
@@ -227,21 +227,21 @@ def response(resp):
227227 # convert the text to dom
228228 dom = html.fromstring(resp.text)
229229
230− instant_answer = dom.xpath('//div[@id="_vBb"]//text()')
230+ instant_answer = eval_xpath(dom, '//div[@id="_vBb"]//text()')
231231 if instant_answer:
232232 results.append({'answer': u' '.join(instant_answer)})
233233 try:
234− results_num = int(dom.xpath('//div[@id="resultStats"]//text()')[0]
234+ results_num = int(eval_xpath(dom, '//div[@id="resultStats"]//text()')[0]
235235 .split()[1].replace(',', ''))
236236 results.append({'number_of_results': results_num})
237237 except:
238238 pass
239239
240240 # parse results
241− for result in dom.xpath(results_xpath):
241+ for result in eval_xpath(dom, results_xpath):
242242 try:
243− title = extract_text(result.xpath(title_xpath)[0])
244− url = parse_url(extract_url(result.xpath(url_xpath), google_url), google_hostname)
243+ title = extract_text(eval_xpath(result, title_xpath)[0])
244+ url = parse_url(extract_url(eval_xpath(result, url_xpath), google_url), google_hostname)
245245 parsed_url = urlparse(url, google_hostname)
246246
247247 # map result
@@ -250,7 +250,7 @@ def response(resp):
250250 continue
251251 # if parsed_url.path.startswith(maps_path) or parsed_url.netloc.startswith(map_hostname_start):
252252 # print "yooooo"*30
253− # x = result.xpath(map_near)
253+ # x = eval_xpath(result, map_near)
254254 # if len(x) > 0:
255255 # # map : near the location
256256 # results = results + parse_map_near(parsed_url, x, google_hostname)
@@ -287,11 +287,11 @@ def response(resp):
287287 continue
288288
289289 # parse suggestion
290− for suggestion in dom.xpath(suggestion_xpath):
290+ for suggestion in eval_xpath(dom, suggestion_xpath):
291291 # append suggestion
292292 results.append({'suggestion': extract_text(suggestion)})
293293
294− for correction in dom.xpath(spelling_suggestion_xpath):
294+ for correction in eval_xpath(dom, spelling_suggestion_xpath):
295295 results.append({'correction': extract_text(correction)})
296296
297297 # return results
@@ -300,9 +300,9 @@ def response(resp):
300300
301301def parse_images(result, google_hostname):
302302 results = []
303− for image in result.xpath(images_xpath):
304− url = parse_url(extract_text(image.xpath(image_url_xpath)[0]), google_hostname)
305− img_src = extract_text(image.xpath(image_img_src_xpath)[0])
303+ for image in eval_xpath(result, images_xpath):
304+ url = parse_url(extract_text(eval_xpath(image, image_url_xpath)[0]), google_hostname)
305+ img_src = extract_text(eval_xpath(image, image_img_src_xpath)[0])
306306
307307 # append result
308308 results.append({'url': url,
@@ -389,10 +389,10 @@ def attributes_to_html(attributes):
389389def _fetch_supported_languages(resp):
390390 supported_languages = {}
391391 dom = html.fromstring(resp.text)
392− options = dom.xpath('//*[@id="langSec"]//input[@name="lr"]')
392+ options = eval_xpath(dom, '//*[@id="langSec"]//input[@name="lr"]')
393393 for option in options:
394− code = option.xpath('./@value')[0].split('_')[-1]
395− name = option.xpath('./@data-name')[0].title()
394+ code = eval_xpath(option, './@value')[0].split('_')[-1]
395+ name = eval_xpath(option, './@data-name')[0].title()
396396 supported_languages[code] = {"name": name}
397397
398398 return supported_languages