mirror of https://github.com/searx/searx
[enh] Allow passing headers/cookies from settings.yml
Example: - engine: xpath - search_url: example.org - headers: {'example_header': 'example_header'} - cookies: {'safesearch': 'off'}
This commit is contained in:
parent
a3e41c3cd6
commit
f8031fb072
|
@ -16,10 +16,14 @@ cached_xpath = ''
|
||||||
cached_url = ''
|
cached_url = ''
|
||||||
soft_max_redirects = 0
|
soft_max_redirects = 0
|
||||||
|
|
||||||
# parameters for engines with paging support
|
cookies = {}
|
||||||
#
|
headers = {}
|
||||||
# number of results on each page
|
'''Some engines might offer different result based on cookies or headers.
|
||||||
# (only needed if the site requires not a page number, but an offset)
|
Possible use-case: To set safesearch cookie or header to moderate.'''
|
||||||
|
|
||||||
|
paging = False
|
||||||
|
'''Engine supports paging [True or False].'''
|
||||||
|
|
||||||
page_size = 1
|
page_size = 1
|
||||||
# number of the first page (usually 0 or 1)
|
# number of the first page (usually 0 or 1)
|
||||||
first_page_num = 1
|
first_page_num = 1
|
||||||
|
@ -32,8 +36,22 @@ def request(query, params):
|
||||||
if paging and search_url.find('{pageno}') >= 0:
|
if paging and search_url.find('{pageno}') >= 0:
|
||||||
fp['pageno'] = (params['pageno'] - 1) * page_size + first_page_num
|
fp['pageno'] = (params['pageno'] - 1) * page_size + first_page_num
|
||||||
|
|
||||||
params['url'] = search_url.format(**fp)
|
safe_search = ''
|
||||||
params['query'] = query
|
if params['safesearch']:
|
||||||
|
safe_search = safe_search_map[params['safesearch']]
|
||||||
|
|
||||||
|
fargs = {
|
||||||
|
'query': urlencode({'q': query})[2:],
|
||||||
|
'lang': lang,
|
||||||
|
'pageno': (params['pageno'] - 1) * page_size + first_page_num,
|
||||||
|
'time_range': time_range,
|
||||||
|
'safe_search': safe_search,
|
||||||
|
}
|
||||||
|
|
||||||
|
params['cookies'] = cookies
|
||||||
|
params['headers'] = headers
|
||||||
|
|
||||||
|
params['url'] = search_url.format(**fargs)
|
||||||
params['soft_max_redirects'] = soft_max_redirects
|
params['soft_max_redirects'] = soft_max_redirects
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
|
Loading…
Reference in New Issue