1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- from urllib import urlencode
- from lxml.html import fromstring
- from searx.utils import html_to_text
- categories = ['general']
- paging = True
- language_support = True
- url = 'https://duckduckgo.com/html?{query}&s={offset}'
- result_xpath = '//div[@class="results_links results_links_deep web-result"]'
- url_xpath = './/a[@class="large"]/@href'
- title_xpath = './/a[@class="large"]//text()'
- content_xpath = './/div[@class="snippet"]//text()'
- def request(query, params):
- offset = (params['pageno'] - 1) * 30
- if params['language'] == 'all':
- locale = 'en-us'
- else:
- locale = params['language'].replace('_','-').lower()
- params['url'] = url.format(
- query=urlencode({'q': query, 'kl': locale}),
- offset=offset)
- return params
- def response(resp):
- results = []
- doc = fromstring(resp.text)
-
- for r in doc.xpath(result_xpath):
- try:
- res_url = r.xpath(url_xpath)[-1]
- except:
- continue
- if not res_url:
- continue
- title = html_to_text(''.join(r.xpath(title_xpath)))
- content = html_to_text(''.join(r.xpath(content_xpath)))
-
- results.append({'title': title,
- 'content': content,
- 'url': res_url})
-
- return results
|