瀏覽代碼

[enh] wikipedia search added

asciimoo 11 年之前
父節點
當前提交
e4b768b6cc
共有 1 個檔案被更改,包括 15 行新增0 行删除
  1. 15
    0
      searx/engines/wikipedia.py

+ 15
- 0
searx/engines/wikipedia.py 查看文件

@@ -0,0 +1,15 @@
1
+from json import loads
2
+
3
+def request(query, params):
4
+    params['url'] = 'http://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=%s&srprop=timestamp&format=json' % query
5
+
6
+    return params
7
+
8
+
9
+def response(resp):
10
+    search_results = loads(resp.text)
11
+    results = []
12
+    for res in search_results.get('query', {}).get('search', []):
13
+        results.append({'url': 'https://en.wikipedia.org/wiki/%s' % res['title'], 'title': res['title']})
14
+    return results
15
+