searxng/searx/engines/duckduckgo.py

20 lines
491 B
Python
Raw Normal View History

2013-10-15 17:11:43 +00:00
from json import loads
2013-10-14 21:09:13 +00:00
def request(query, params):
2013-10-15 17:11:43 +00:00
params['url'] = 'https://duckduckgo.com/d.js?q=%s&l=us-en&p=1&s=0' % query
2013-10-14 21:09:13 +00:00
return params
def response(resp):
2013-10-15 17:11:43 +00:00
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