|
@@ -1,13 +1,15 @@
|
1
|
1
|
from lxml import etree
|
2
|
2
|
from requests import get
|
3
|
3
|
from json import loads
|
|
4
|
+from urllib import urlencode
|
4
|
5
|
|
5
|
6
|
|
6
|
7
|
def dbpedia(query):
|
7
|
8
|
# dbpedia autocompleter
|
8
|
|
- autocomplete_url = 'http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryString={q}' # noqa
|
|
9
|
+ autocomplete_url = 'http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?' # noqa
|
9
|
10
|
|
10
|
|
- response = get(autocomplete_url.format(q=query))
|
|
11
|
+ response = get(autocomplete_url
|
|
12
|
+ + urlencode(dict(QueryString=query)))
|
11
|
13
|
|
12
|
14
|
results = []
|
13
|
15
|
|
|
@@ -21,14 +23,15 @@ def dbpedia(query):
|
21
|
23
|
|
22
|
24
|
def google(query):
|
23
|
25
|
# google autocompleter
|
24
|
|
- autocomplete_url = 'http://suggestqueries.google.com/complete/search?client=toolbar&q={q}' # noqa
|
|
26
|
+ autocomplete_url = 'http://suggestqueries.google.com/complete/search?client=toolbar&' # noqa
|
25
|
27
|
|
26
|
|
- response = get(autocomplete_url.format(q=query))
|
|
28
|
+ response = get(autocomplete_url
|
|
29
|
+ + urlencode(dict(q=query)))
|
27
|
30
|
|
28
|
31
|
results = []
|
29
|
32
|
|
30
|
33
|
if response.ok:
|
31
|
|
- dom = etree.fromstring(response.content)
|
|
34
|
+ dom = etree.fromstring(response.text)
|
32
|
35
|
results = dom.xpath('//suggestion/@data')
|
33
|
36
|
|
34
|
37
|
return results
|
|
@@ -36,9 +39,9 @@ def google(query):
|
36
|
39
|
|
37
|
40
|
def wikipedia(query):
|
38
|
41
|
# wikipedia autocompleter
|
39
|
|
- url = 'https://en.wikipedia.org/w/api.php?action=opensearch&search={q}&limit=10&namespace=0&format=json' # noqa
|
|
42
|
+ url = 'https://en.wikipedia.org/w/api.php?action=opensearch&{0}&limit=10&namespace=0&format=json' # noqa
|
40
|
43
|
|
41
|
|
- resp = loads(get(url.format(q=query)).text)
|
|
44
|
+ resp = loads(get(url.format(urlencode(dict(q=query)))).text)
|
42
|
45
|
return resp[1]
|
43
|
46
|
|
44
|
47
|
|