asciimoo 11 лет назад
Родитель
Сommit
e91e4e7fdb
1 измененных файлов: 32 добавлений и 0 удалений
  1. 32
    0
      searx/engines/duckduckgo_definitions.py

+ 32
- 0
searx/engines/duckduckgo_definitions.py Просмотреть файл

@@ -0,0 +1,32 @@
1
+import json
2
+from searx import base_result_template
3
+
4
+def request(query, params):
5
+    params['url'] = 'http://api.duckduckgo.com/?q=%s&format=json&pretty=0' % query
6
+    return params
7
+
8
+
9
+def response(resp):
10
+    search_res = json.loads(resp.text)
11
+    results = []
12
+    if 'Definition' in search_res:
13
+        res = {'title'   : search_res.get('Heading', '')
14
+              ,'content' : search_res.get('Definition', '')
15
+              ,'url'     : search_res.get('AbstractURL', '')
16
+              }
17
+        results.append(base_result_template.format(**res))
18
+
19
+    return results
20
+
21
+#from lxml import html
22
+#def request(query, params):
23
+#    params['method']    = 'POST'
24
+#    params['url']       = 'https://duckduckgo.com/html'
25
+#    params['data']['q'] = query
26
+#    return params
27
+#
28
+#
29
+#def response(resp):
30
+#    dom = html.fromstring(resp.text)
31
+#    results = dom.xpath('//div[@class="results_links results_links_deep web-result"]')
32
+#    return [html.tostring(x) for x in results]