diff options
Diffstat (limited to 'searx/engines/duckduckgo.py')
-rw-r--r-- | searx/engines/duckduckgo.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/searx/engines/duckduckgo.py b/searx/engines/duckduckgo.py index ed93829ba..74c17a31b 100644 --- a/searx/engines/duckduckgo.py +++ b/searx/engines/duckduckgo.py @@ -1,14 +1,19 @@ -from lxml import html +from json import loads def request(query, params): - params['method'] = 'POST' - params['url'] = 'https://duckduckgo.com/html' - params['data']['q'] = query + params['url'] = 'https://duckduckgo.com/d.js?q=%s&l=us-en&p=1&s=0' % query return params def response(resp): - dom = html.fromstring(resp.text) - results = dom.xpath('//div[@class="results_links results_links_deep web-result"]') - return [html.tostring(x) for x in results] + results = [] + search_res = loads(resp.text[resp.text.find('[{'):-2])[:-1] + for r in search_res: + if not r.get('t'): + continue + results.append({'title': r['t'] + ,'content': r['a'] + ,'url': r['u'] + }) + return results |