@@ -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
@@ -226,21 +226,21 @@ def response(resp):
226226 # convert the text to dom
227227 dom = html.fromstring(resp.text)
228228
229− instant_answer = dom.xpath('//div[@id="_vBb"]//text()')
229+ instant_answer = eval_xpath(dom, '//div[@id="_vBb"]//text()')
230230 if instant_answer:
231231 results.append({'answer': u' '.join(instant_answer)})
232232 try:
233− results_num = int(dom.xpath('//div[@id="resultStats"]//text()')[0]
233+ results_num = int(eval_xpath(dom, '//div[@id="resultStats"]//text()')[0]
234234 .split()[1].replace(',', ''))
235235 results.append({'number_of_results': results_num})
236236 except:
237237 pass
238238
239239 # parse results
240− for result in dom.xpath(results_xpath):
240+ for result in eval_xpath(dom, results_xpath):
241241 try:
242− title = extract_text(result.xpath(title_xpath)[0])
243− url = parse_url(extract_url(result.xpath(url_xpath), google_url), google_hostname)
242+ title = extract_text(eval_xpath(result, title_xpath)[0])
243+ url = parse_url(extract_url(eval_xpath(result, url_xpath), google_url), google_hostname)
244244 parsed_url = urlparse(url, google_hostname)
245245
246246 # map result
@@ -249,7 +249,7 @@ def response(resp):
249249 continue
250250 # if parsed_url.path.startswith(maps_path) or parsed_url.netloc.startswith(map_hostname_start):
251251 # print "yooooo"*30
252− # x = result.xpath(map_near)
252+ # x = eval_xpath(result, map_near)
253253 # if len(x) > 0:
254254 # # map : near the location
255255 # results = results + parse_map_near(parsed_url, x, google_hostname)
@@ -286,11 +286,11 @@ def response(resp):
286286 continue
287287
288288 # parse suggestion
289− for suggestion in dom.xpath(suggestion_xpath):
289+ for suggestion in eval_xpath(dom, suggestion_xpath):
290290 # append suggestion
291291 results.append({'suggestion': extract_text(suggestion)})
292292
293− for correction in dom.xpath(spelling_suggestion_xpath):
293+ for correction in eval_xpath(dom, spelling_suggestion_xpath):
294294 results.append({'correction': extract_text(correction)})
295295
296296 # return results
@@ -299,9 +299,9 @@ def response(resp):
299299
300300def parse_images(result, google_hostname):
301301 results = []
302− for image in result.xpath(images_xpath):
303− url = parse_url(extract_text(image.xpath(image_url_xpath)[0]), google_hostname)
304− img_src = extract_text(image.xpath(image_img_src_xpath)[0])
302+ for image in eval_xpath(result, images_xpath):
303+ url = parse_url(extract_text(eval_xpath(image, image_url_xpath)[0]), google_hostname)
304+ img_src = extract_text(eval_xpath(image, image_img_src_xpath)[0])
305305
306306 # append result
307307 results.append({'url': url,
@@ -388,10 +388,10 @@ def attributes_to_html(attributes):
388388def _fetch_supported_languages(resp):
389389 supported_languages = {}
390390 dom = html.fromstring(resp.text)
391− options = dom.xpath('//*[@id="langSec"]//input[@name="lr"]')
391+ options = eval_xpath(dom, '//*[@id="langSec"]//input[@name="lr"]')
392392 for option in options:
393− code = option.xpath('./@value')[0].split('_')[-1]
394− name = option.xpath('./@data-name')[0].title()
393+ code = eval_xpath(option, './@value')[0].split('_')[-1]
394+ name = eval_xpath(option, './@data-name')[0].title()
395395 supported_languages[code] = {"name": name}
396396
397397 return supported_languages