diff options
author | asciimoo <asciimoo@gmail.com> | 2013-10-15 19:11:43 +0200 |
---|---|---|
committer | asciimoo <asciimoo@gmail.com> | 2013-10-15 19:11:43 +0200 |
commit | d793c2733c7aac3aacf40f3f5cf9fc0919305e76 (patch) | |
tree | 0a6f500a17f14d9da4921ad8fbeaf63f1ebccac1 /searx/engines/duckduckgo.py | |
parent | c3b7ed868783691d5678977779e91568cc2f2fec (diff) | |
download | searxng-d793c2733c7aac3aacf40f3f5cf9fc0919305e76.tar.gz searxng-d793c2733c7aac3aacf40f3f5cf9fc0919305e76.zip |
[enh] engine types
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 |