Browse Source

[enh] bing, google paging support

asciimoo 11 years ago
parent
commit
ca271fd861
2 changed files with 12 additions and 4 deletions
  1. 6
    2
      searx/engines/bing.py
  2. 6
    2
      searx/engines/google.py

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

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

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

5
 
5
 
6
 categories = ['general']
6
 categories = ['general']
7
 
7
 
8
+paging = True
9
+
8
 url = 'https://ajax.googleapis.com/'
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
 def request(query, params):
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
     return params
18
     return params
15
 
19
 
16
 
20