Sfoglia il codice sorgente

[enh] bing, google paging support

asciimoo 11 anni fa
parent
commit
ca271fd861
2 ha cambiato i file con 12 aggiunte e 4 eliminazioni
  1. 6
    2
      searx/engines/bing.py
  2. 6
    2
      searx/engines/google.py

+ 6
- 2
searx/engines/bing.py Vedi File

@@ -3,13 +3,17 @@ from urllib import urlencode
3 3
 from cgi import escape
4 4
 
5 5
 base_url = 'http://www.bing.com/'
6
-search_string = 'search?{query}'
6
+search_string = 'search?{query}&first={offset}'
7 7
 locale = 'en-US'  # see http://msdn.microsoft.com/en-us/library/dd251064.aspx
8 8
 
9
+paging = True
10
+
9 11
 
10 12
 def request(query, params):
13
+    offset = (params['pageno'] - 1) * 10 + 1
11 14
     search_path = search_string.format(
12
-        query=urlencode({'q': query, 'setmkt': locale}))
15
+        query=urlencode({'q': query, 'setmkt': locale}),
16
+        offset=offset)
13 17
     #if params['category'] == 'images':
14 18
     #    params['url'] = base_url + 'images/' + search_path
15 19
     params['url'] = base_url + search_path

+ 6
- 2
searx/engines/google.py Vedi File

@@ -5,12 +5,16 @@ from json import loads
5 5
 
6 6
 categories = ['general']
7 7
 
8
+paging = True
9
+
8 10
 url = 'https://ajax.googleapis.com/'
9
-search_url = url + 'ajax/services/search/web?v=1.0&start=0&rsz=large&safe=off&filter=off&{query}'  # noqa
11
+search_url = url + 'ajax/services/search/web?v=1.0&start={offset}&rsz=large&safe=off&filter=off&{query}'  # noqa
10 12
 
11 13
 
12 14
 def request(query, params):
13
-    params['url'] = search_url.format(query=urlencode({'q': query}))
15
+    offset = (params['pageno'] - 1) * 8
16
+    params['url'] = search_url.format(offset=offset,
17
+                                      query=urlencode({'q': query}))
14 18
     return params
15 19
 
16 20