summaryrefslogtreecommitdiff
path: root/searx/engines/duckduckgo.py
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2020-10-09 15:01:40 +0200
committerAlexandre Flament <alex@al-f.net>2020-10-09 16:00:42 +0200
commitcfd21bc4751e48e0c27539012bed42aca8322a0d (patch)
treeaff0c4a95f5ad69fe446e92c0511fb3098166668 /searx/engines/duckduckgo.py
parenta05c660e3036ad8d02072fc6731af54c2ed6151c (diff)
downloadsearxng-cfd21bc4751e48e0c27539012bed42aca8322a0d.tar.gz
searxng-cfd21bc4751e48e0c27539012bed42aca8322a0d.zip
[fix] fix duckduckgo engine
- remove paging support: a "vqd" parameter is required between each request. This parameter is uniq for each request - update the URL (no redirect), use the POST method - language support: works if there is no more than request per minute, otherwise it is ignored !
Diffstat (limited to 'searx/engines/duckduckgo.py')
-rw-r--r--searx/engines/duckduckgo.py43
1 files changed, 13 insertions, 30 deletions
diff --git a/searx/engines/duckduckgo.py b/searx/engines/duckduckgo.py
index 4a42fe7f1..a53972325 100644
--- a/searx/engines/duckduckgo.py
+++ b/searx/engines/duckduckgo.py
@@ -21,7 +21,7 @@ from searx.utils import extract_text, match_language, eval_xpath
# engine dependent config
categories = ['general']
-paging = True
+paging = False
language_support = True
supported_languages_url = 'https://duckduckgo.com/util/u172.js'
time_range_support = True
@@ -37,9 +37,7 @@ language_aliases = {
}
# search-url
-url = 'https://duckduckgo.com/html?{query}&s={offset}&dc={dc_param}'
-time_range_url = '&df={range}'
-
+url = 'https://html.duckduckgo.com/html'
time_range_dict = {'day': 'd',
'week': 'w',
'month': 'm'}
@@ -65,36 +63,21 @@ def get_region_code(lang, lang_list=[]):
def request(query, params):
- if params['time_range'] not in (None, 'None', '') and params['time_range'] not in time_range_dict:
+ if params['time_range'] is not None and params['time_range'] not in time_range_dict:
return params
- offset = (params['pageno'] - 1) * 30
+ params['url'] = url
+ params['method'] = 'POST'
+ params['data']['b'] = ''
+ params['data']['q'] = query
+ params['data']['df'] = ''
region_code = get_region_code(params['language'], supported_languages)
- params['url'] = 'https://duckduckgo.com/html/'
- if params['pageno'] > 1:
- params['method'] = 'POST'
- params['data']['q'] = query
- params['data']['s'] = offset
- params['data']['dc'] = 30
- params['data']['nextParams'] = ''
- params['data']['v'] = 'l'
- params['data']['o'] = 'json'
- params['data']['api'] = '/d.js'
- if params['time_range'] in time_range_dict:
- params['data']['df'] = time_range_dict[params['time_range']]
- if region_code:
- params['data']['kl'] = region_code
- else:
- if region_code:
- params['url'] = url.format(
- query=urlencode({'q': query, 'kl': region_code}), offset=offset, dc_param=offset)
- else:
- params['url'] = url.format(
- query=urlencode({'q': query}), offset=offset, dc_param=offset)
-
- if params['time_range'] in time_range_dict:
- params['url'] += time_range_url.format(range=time_range_dict[params['time_range']])
+ if region_code:
+ params['data']['kl'] = region_code
+ params['cookies']['kl'] = region_code
+ if params['time_range'] in time_range_dict:
+ params['data']['df'] = time_range_dict[params['time_range']]
return params