diff options
author | Cqoicebordel <Cqoicebordel@users.noreply.github.com> | 2015-06-01 00:00:32 +0200 |
---|---|---|
committer | Cqoicebordel <Cqoicebordel@users.noreply.github.com> | 2015-06-01 00:00:32 +0200 |
commit | 884eeb8541e0a4cf3d65c2a17e1c2f788cab7fb1 (patch) | |
tree | a3179b4a58b34bde03e2a140c5511567008af3a9 /searx/engines/qwant.py | |
parent | f965c978222cf48e8dd4b7dd6c9a28ccca9bc62f (diff) | |
download | searxng-884eeb8541e0a4cf3d65c2a17e1c2f788cab7fb1.tar.gz searxng-884eeb8541e0a4cf3d65c2a17e1c2f788cab7fb1.zip |
New Qwant engines
- Web
- Images
- News
- Social media
Diffstat (limited to 'searx/engines/qwant.py')
-rw-r--r-- | searx/engines/qwant.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/searx/engines/qwant.py b/searx/engines/qwant.py new file mode 100644 index 000000000..91c12a19e --- /dev/null +++ b/searx/engines/qwant.py @@ -0,0 +1,66 @@ +""" + Qwant (Web) + + @website https://qwant.com/ + @provide-api not officially (https://api.qwant.com/api/search/) + + @using-api yes + @results JSON + @stable yes + @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://api.qwant.com/api/search/web?count=10&offset={offset}&f=&{query}' + + +# do search-request +def request(query, params): + offset = (params['pageno'] - 1) * 10 + + params['url'] = url.format(query=urlencode({'q': query}), + offset=offset) + + # add language tag if specified + if params['language'] != 'all': + params['url'] += '&locale=' + params['language'].lower() + + return params + + +# get response from search-request +def response(resp): + results = [] + + search_results = loads(resp.text) + + # return empty array if there are no results + if 'data' not in search_results: + return [] + + data = search_results.get('data', {}) + + res = data.get('result', {}) + + # parse results + for result in res.get('items', {}): + + title = result['title'] + res_url = result['url'] + content = result['desc'] + + # append result + results.append({'title': title, + 'content': content, + 'url': res_url}) + + # return results + return results |