summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2017-01-27 13:47:59 +0000
committerGitHub <noreply@github.com>2017-01-27 13:47:59 +0000
commite67dfaaac7991b299dd9c33ae69e7028cd8f6589 (patch)
tree506ed1dd4a527e37c902035d84215ed2be2577d9 /searx/engines
parent7a16aca346c14994f304a6961c55b63ab260265a (diff)
parentee1d44caf9bb9b0fb1b3bafbcbff74486b5449e8 (diff)
Merge branch 'master' into flask_perimeter
Diffstat (limited to 'searx/engines')
-rw-r--r--searx/engines/google.py10
-rw-r--r--searx/engines/xpath.py8
2 files changed, 14 insertions, 4 deletions
diff --git a/searx/engines/google.py b/searx/engines/google.py
index 2fa638d73..e14e9e702 100644
--- a/searx/engines/google.py
+++ b/searx/engines/google.py
@@ -112,6 +112,7 @@ title_xpath = './/h3'
content_xpath = './/span[@class="st"]'
content_misc_xpath = './/div[@class="f slp"]'
suggestion_xpath = '//p[@class="_Bmc"]'
+spelling_suggestion_xpath = '//a[@class="spell"]'
# map : detail location
map_address_xpath = './/div[@class="s"]//table//td[2]/span/text()'
@@ -220,6 +221,12 @@ def response(resp):
instant_answer = dom.xpath('//div[@id="_vBb"]//text()')
if instant_answer:
results.append({'answer': u' '.join(instant_answer)})
+ try:
+ results_num = int(dom.xpath('//div[@id="resultStats"]//text()')[0]
+ .split()[1].replace(',', ''))
+ results.append({'number_of_results': results_num})
+ except:
+ pass
# parse results
for result in dom.xpath(results_xpath):
@@ -275,6 +282,9 @@ def response(resp):
# append suggestion
results.append({'suggestion': extract_text(suggestion)})
+ for correction in dom.xpath(spelling_suggestion_xpath):
+ results.append({'correction': extract_text(correction)})
+
# return results
return results
diff --git a/searx/engines/xpath.py b/searx/engines/xpath.py
index 18943bba4..0d39b28a8 100644
--- a/searx/engines/xpath.py
+++ b/searx/engines/xpath.py
@@ -31,8 +31,6 @@ if xpath_results is a string element, then it's already done
def extract_text(xpath_results):
if type(xpath_results) == list:
# it's list of result : concat everything using recursive call
- if not xpath_results:
- raise Exception('Empty url resultset')
result = ''
for e in xpath_results:
result = result + extract_text(e)
@@ -48,6 +46,8 @@ def extract_text(xpath_results):
def extract_url(xpath_results, search_url):
+ if xpath_results == []:
+ raise Exception('Empty url resultset')
url = extract_text(xpath_results)
if url.startswith('//'):
@@ -103,8 +103,8 @@ def response(resp):
if results_xpath:
for result in dom.xpath(results_xpath):
url = extract_url(result.xpath(url_xpath), search_url)
- title = extract_text(result.xpath(title_xpath)[0])
- content = extract_text(result.xpath(content_xpath)[0])
+ title = extract_text(result.xpath(title_xpath))
+ content = extract_text(result.xpath(content_xpath))
results.append({'url': url, 'title': title, 'content': content})
else:
for url, title, content in zip(