diff options
author | Adam Tauber <asciimoo@gmail.com> | 2014-03-29 17:04:33 +0100 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2014-03-29 17:04:33 +0100 |
commit | 8e2d996e273f58d96870d1eef45139c924434236 (patch) | |
tree | 7af995d5c20967d0a0b8314c1615d50653eeea53 /searx/autocomplete.py | |
parent | 879bac8adb181593989a132fabd607f50096473a (diff) | |
download | searxng-8e2d996e273f58d96870d1eef45139c924434236.tar.gz searxng-8e2d996e273f58d96870d1eef45139c924434236.zip |
[fix] autocomplete encoding
Diffstat (limited to 'searx/autocomplete.py')
-rw-r--r-- | searx/autocomplete.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/searx/autocomplete.py b/searx/autocomplete.py index e9cdc8ba9..828e85e42 100644 --- a/searx/autocomplete.py +++ b/searx/autocomplete.py @@ -1,13 +1,15 @@ from lxml import etree from requests import get from json import loads +from urllib import urlencode def dbpedia(query): # dbpedia autocompleter - autocomplete_url = 'http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryString={q}' # noqa + autocomplete_url = 'http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?' # noqa - response = get(autocomplete_url.format(q=query)) + response = get(autocomplete_url + + urlencode(dict(QueryString=query))) results = [] @@ -21,14 +23,15 @@ def dbpedia(query): def google(query): # google autocompleter - autocomplete_url = 'http://suggestqueries.google.com/complete/search?client=toolbar&q={q}' # noqa + autocomplete_url = 'http://suggestqueries.google.com/complete/search?client=toolbar&' # noqa - response = get(autocomplete_url.format(q=query)) + response = get(autocomplete_url + + urlencode(dict(q=query))) results = [] if response.ok: - dom = etree.fromstring(response.content) + dom = etree.fromstring(response.text) results = dom.xpath('//suggestion/@data') return results @@ -36,9 +39,9 @@ def google(query): def wikipedia(query): # wikipedia autocompleter - url = 'https://en.wikipedia.org/w/api.php?action=opensearch&search={q}&limit=10&namespace=0&format=json' # noqa + url = 'https://en.wikipedia.org/w/api.php?action=opensearch&{0}&limit=10&namespace=0&format=json' # noqa - resp = loads(get(url.format(q=query)).text) + resp = loads(get(url.format(urlencode(dict(q=query)))).text) return resp[1] |