Browse Source

[fix] gigablast params ++ json response format

Adam Tauber 9 years ago
parent
commit
37035b7a40
1 changed files with 12 additions and 16 deletions
  1. 12
    16
      searx/engines/gigablast.py

+ 12
- 16
searx/engines/gigablast.py View File

10
  @parse       url, title, content
10
  @parse       url, title, content
11
 """
11
 """
12
 
12
 
13
-from urllib import urlencode
14
 from cgi import escape
13
 from cgi import escape
15
-from lxml import etree
14
+from json import loads
16
 from random import randint
15
 from random import randint
17
 from time import time
16
 from time import time
17
+from urllib import urlencode
18
 
18
 
19
 # engine dependent config
19
 # engine dependent config
20
 categories = ['general']
20
 categories = ['general']
27
 base_url = 'https://gigablast.com/'
27
 base_url = 'https://gigablast.com/'
28
 search_string = 'search?{query}'\
28
 search_string = 'search?{query}'\
29
     '&n={number_of_results}'\
29
     '&n={number_of_results}'\
30
+    '&c=main'\
30
     '&s={offset}'\
31
     '&s={offset}'\
31
-    '&format=xml'\
32
+    '&format=json'\
32
     '&qh=0'\
33
     '&qh=0'\
33
-    '&rxiyd={rxiyd}'\
34
-    '&rand={rand}'\
34
+    '&rxiwd={rxiwd}'\
35
     '&qlang={lang}'\
35
     '&qlang={lang}'\
36
     '&ff={safesearch}'
36
     '&ff={safesearch}'
37
 
37
 
59
     search_path = search_string.format(query=urlencode({'q': query}),
59
     search_path = search_string.format(query=urlencode({'q': query}),
60
                                        offset=offset,
60
                                        offset=offset,
61
                                        number_of_results=number_of_results,
61
                                        number_of_results=number_of_results,
62
-                                       rxiyd=randint(10000, 10000000),
63
-                                       rand=int(time()),
62
+                                       rxiwd=1,
63
+                                       #  rand=int(time()),
64
                                        lang=language,
64
                                        lang=language,
65
                                        safesearch=safesearch)
65
                                        safesearch=safesearch)
66
 
66
 
73
 def response(resp):
73
 def response(resp):
74
     results = []
74
     results = []
75
 
75
 
76
-    dom = etree.fromstring(resp.content)
77
-
78
     # parse results
76
     # parse results
79
-    for result in dom.xpath(results_xpath):
80
-        url = result.xpath(url_xpath)[0].text
81
-        title = result.xpath(title_xpath)[0].text
82
-        content = escape(result.xpath(content_xpath)[0].text)
77
+    response_json = loads(resp.text)
83
 
78
 
79
+    for result in response_json['results']:
84
         # append result
80
         # append result
85
-        results.append({'url': url,
86
-                        'title': title,
87
-                        'content': content})
81
+        results.append({'url': result['url'],
82
+                        'title': escape(result['title']),
83
+                        'content': escape(result['sum'])})
88
 
84
 
89
     # return results
85
     # return results
90
     return results
86
     return results