on master help sign in
Merge pull request #2559 from dalf/upd-duckduckgo
ddab00aAlexandre Flament
docs/dev/engine_overview.rst+1
@@ -169,6 +169,7 @@ headers set HTTP header information
169data set HTTP data information
169data set HTTP data information
170cookies set HTTP cookies
170cookies set HTTP cookies
171verify bool Performing SSL-Validity check
171verify bool Performing SSL-Validity check
172+allow_redirects bool Follow redirects
172max_redirects int maximum redirects, hard limit
173max_redirects int maximum redirects, hard limit
173soft_max_redirects int maximum redirects, soft limit. Record an error but don't stop the engine
174soft_max_redirects int maximum redirects, soft limit. Record an error but don't stop the engine
174raise_for_httperror bool True by default: raise an exception if the HTTP code of response is >= 300
175raise_for_httperror bool True by default: raise an exception if the HTTP code of response is >= 300
searx/engines/duckduckgo.py+7−1
@@ -75,12 +75,18 @@ def request(query, params):
75 params['data']['kl'] = region_code
75 params['data']['kl'] = region_code
76 params['cookies']['kl'] = region_code
76 params['cookies']['kl'] = region_code
77
77
78+ if params['time_range'] in time_range_dict:
78− params['data']['df'] = time_range_dict.get(params['time_range'], '')
79+ params['data']['df'] = time_range_dict[params['time_range']]
80+
81+ params['allow_redirects'] = False
79 return params
82 return params
80
83
81
84
82# get response from search-request
85# get response from search-request
83def response(resp):
86def response(resp):
87+ if resp.status_code == 303:
88+ return []
89+
84 # ping
90 # ping
85 headers_ping = dict_subset(resp.request.headers, ['User-Agent', 'Accept-Encoding', 'Accept', 'Cookie'])
91 headers_ping = dict_subset(resp.request.headers, ['User-Agent', 'Accept-Encoding', 'Accept', 'Cookie'])
86 get(url_ping, headers=headers_ping)
92 get(url_ping, headers=headers_ping)
searx/search/processors/online.py+4
@@ -73,6 +73,10 @@ class OnlineProcessor(EngineProcessor):
73 if max_redirects:
73 if max_redirects:
74 request_args['max_redirects'] = max_redirects
74 request_args['max_redirects'] = max_redirects
75
75
76+ # allow_redirects
77+ if 'allow_redirects' in params:
78+ request_args['allow_redirects'] = params['allow_redirects']
79+
76 # soft_max_redirects
80 # soft_max_redirects
77 soft_max_redirects = params.get('soft_max_redirects', max_redirects or 0)
81 soft_max_redirects = params.get('soft_max_redirects', max_redirects or 0)
78
82