@@ -5,7 +5,8 @@
55
66from lxml.html import fromstring
77from json import loads
8−from searx.utils import extract_text, match_language, eval_xpath
8+from searx.utils import extract_text, match_language, eval_xpath, dict_subset
9+from searx.poolrequests import get
910
1011# about
1112about = {
@@ -35,6 +36,7 @@ language_aliases = {
3536
3637# search-url
3738url = 'https://html.duckduckgo.com/html'
39+url_ping = 'https://duckduckgo.com/t/sl_h'
3840time_range_dict = {'day': 'd',
3941 'week': 'w',
4042 'month': 'm'}
@@ -65,27 +67,27 @@ def request(query, params):
6567
6668 params['url'] = url
6769 params['method'] = 'POST'
68− params['data']['b'] = ''
6970 params['data']['q'] = query
70− params['data']['df'] = ''
71+ params['data']['b'] = ''
7172
7273 region_code = get_region_code(params['language'], supported_languages)
7374 if region_code:
7475 params['data']['kl'] = region_code
7576 params['cookies']['kl'] = region_code
76− if params['time_range'] in time_range_dict:
77− params['data']['df'] = time_range_dict[params['time_range']]
7877
78+ params['data']['df'] = time_range_dict.get(params['time_range'], '')
7979 return params
8080
8181
8282# get response from search-request
8383def response(resp):
84− results = []
84+ # ping
85+ headers_ping = dict_subset(resp.request.headers, ['User-Agent', 'Accept-Encoding', 'Accept', 'Cookie'])
86+ get(url_ping, headers=headers_ping)
8587
88+ # parse the response
89+ results = []
8690 doc = fromstring(resp.text)
87−
88− # parse results
8991 for i, r in enumerate(eval_xpath(doc, result_xpath)):
9092 if i >= 30:
9193 break