ソースを参照

[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,7 +13,7 @@
13 13
 import json
14 14
 from cgi import escape
15 15
 from urllib import urlencode
16
-from urlparse import urlparse
16
+from urlparse import urlparse, urljoin
17 17
 from datetime import datetime
18 18
 
19 19
 # engine dependent config
@@ -21,7 +21,8 @@ categories = ['general', 'images', 'news', 'social media']
21 21
 page_size = 25
22 22
 
23 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 28
 # do search-request
@@ -52,7 +53,7 @@ def response(resp):
52 53
 
53 54
         # extract post information
54 55
         params = {
55
-            'url': data['url'],
56
+            'url': urljoin(base_url, data['permalink']),
56 57
             'title': data['title']
57 58
         }
58 59
 
@@ -61,6 +62,7 @@ def response(resp):
61 62
         url_info = urlparse(thumbnail)
62 63
         # netloc & path
63 64
         if url_info[1] != '' and url_info[2] != '':
65
+            params['img_src'] = data['url']
64 66
             params['thumbnail_src'] = thumbnail
65 67
             params['template'] = 'images.html'
66 68
             img_results.append(params)