[enh] engine types

This commit is contained in:
asciimoo 2013-10-15 19:11:43 +02:00
parent c3b7ed8687
commit d793c2733c
7 changed files with 34 additions and 29 deletions

View file

@ -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