浏览代码

[fix] incorrect URLs in Reddit results - closes #538

Kirill Isakov 9 年前
父节点
当前提交
4eeb5fb76b
共有 1 个文件被更改,包括 5 次插入3 次删除
  1. 5
    3
      searx/engines/reddit.py

+ 5
- 3
searx/engines/reddit.py 查看文件

13
 import json
13
 import json
14
 from cgi import escape
14
 from cgi import escape
15
 from urllib import urlencode
15
 from urllib import urlencode
16
-from urlparse import urlparse
16
+from urlparse import urlparse, urljoin
17
 from datetime import datetime
17
 from datetime import datetime
18
 
18
 
19
 # engine dependent config
19
 # engine dependent config
21
 page_size = 25
21
 page_size = 25
22
 
22
 
23
 # search-url
23
 # search-url
24
-search_url = 'https://www.reddit.com/search.json?{query}'
24
+base_url = 'https://www.reddit.com/'
25
+search_url = base_url + 'search.json?{query}'
25
 
26
 
26
 
27
 
27
 # do search-request
28
 # do search-request
52
 
53
 
53
         # extract post information
54
         # extract post information
54
         params = {
55
         params = {
55
-            'url': data['url'],
56
+            'url': urljoin(base_url, data['permalink']),
56
             'title': data['title']
57
             'title': data['title']
57
         }
58
         }
58
 
59
 
61
         url_info = urlparse(thumbnail)
62
         url_info = urlparse(thumbnail)
62
         # netloc & path
63
         # netloc & path
63
         if url_info[1] != '' and url_info[2] != '':
64
         if url_info[1] != '' and url_info[2] != '':
65
+            params['img_src'] = data['url']
64
             params['thumbnail_src'] = thumbnail
66
             params['thumbnail_src'] = thumbnail
65
             params['template'] = 'images.html'
67
             params['template'] = 'images.html'
66
             img_results.append(params)
68
             img_results.append(params)