summaryrefslogtreecommitdiff
path: root/searx/engines/google.py
diff options
context:
space:
mode:
authorThomas Pointhuber <thomas.pointhuber@gmx.at>2014-09-01 15:10:05 +0200
committerThomas Pointhuber <thomas.pointhuber@gmx.at>2014-09-01 15:10:05 +0200
commit144f89bf785408a193d09f659a5442032c06de74 (patch)
treebd4a3936e82ab2bde8b4d1be709e4988c2e6bfbe /searx/engines/google.py
parentcdf74fe563f24facec5bb487b5b3c6f599b08934 (diff)
downloadsearxng-144f89bf785408a193d09f659a5442032c06de74.tar.gz
searxng-144f89bf785408a193d09f659a5442032c06de74.zip
add comments to google-engines
Diffstat (limited to 'searx/engines/google.py')
-rw-r--r--searx/engines/google.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/searx/engines/google.py b/searx/engines/google.py
index 2c6a98af3..80c7cc746 100644
--- a/searx/engines/google.py
+++ b/searx/engines/google.py
@@ -1,37 +1,57 @@
-#!/usr/bin/env python
+## Google (Web)
+#
+# @website https://www.google.com
+# @provide-api yes (https://developers.google.com/web-search/docs/), deprecated!
+#
+# @using-api yes
+# @results JSON
+# @stable yes (but deprecated)
+# @parse url, title, content
from urllib import urlencode
from json import loads
+# engine dependent config
categories = ['general']
+paging = True
+language_support = True
+# search-url
url = 'https://ajax.googleapis.com/'
search_url = url + 'ajax/services/search/web?v=2.0&start={offset}&rsz=large&safe=off&filter=off&{query}&hl={language}' # noqa
-paging = True
-language_support = True
-
+# do search-request
def request(query, params):
offset = (params['pageno'] - 1) * 8
+
language = 'en-US'
if params['language'] != 'all':
language = params['language'].replace('_', '-')
+
params['url'] = search_url.format(offset=offset,
query=urlencode({'q': query}),
language=language)
+
return params
+# get response from search-request
def response(resp):
results = []
+
search_res = loads(resp.text)
+ # return empty array if there are no results
if not search_res.get('responseData', {}).get('results'):
return []
+ # parse results
for result in search_res['responseData']['results']:
+ # append result
results.append({'url': result['unescapedUrl'],
'title': result['titleNoFormatting'],
'content': result['content']})
+
+ # return results
return results