diff options
author | Bnyro <bnyro@tutanota.com> | 2024-01-12 15:49:55 +0100 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2024-01-15 19:23:26 +0100 |
commit | 0a78f59aba6cf57e6eaf50b34a3c949201ce5175 (patch) | |
tree | 044c3e04d4268ded89f32db6bae71e4951d4f0dd /searx | |
parent | 87f18b98ec23db87101760ce69bbbbe856a33520 (diff) | |
download | searxng-0a78f59aba6cf57e6eaf50b34a3c949201ce5175.tar.gz searxng-0a78f59aba6cf57e6eaf50b34a3c949201ce5175.zip |
[fix] presearch: safesearch, time ranges, crash when no result found
Diffstat (limited to 'searx')
-rw-r--r-- | searx/engines/presearch.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/searx/engines/presearch.py b/searx/engines/presearch.py index 1e20465ed..42429a4fc 100644 --- a/searx/engines/presearch.py +++ b/searx/engines/presearch.py @@ -30,6 +30,7 @@ about = { "results": "JSON", } paging = True +safesearch = True time_range_support = True categories = ["general", "web"] # general, images, videos, news @@ -45,18 +46,18 @@ def init(_): raise ValueError(f'presearch search_type: {search_type}') -def _get_request_id(query, page, time_range, safesearch): +def _get_request_id(query, page, time_range, safesearch_param): args = { "q": query, "page": page, } if time_range: - args["time_range"] = time_range + args["time"] = time_range url = f"{base_url}/{search_type}?{urlencode(args)}" headers = { 'User-Agent': gen_useragent(), - 'Cookie': f"b=1;presearch_session=;use_safe_search={safesearch_map[safesearch]}", + 'Cookie': f"b=1;presearch_session=;use_safe_search={safesearch_map[safesearch_param]}", } resp_text = get(url, headers=headers).text # type: ignore @@ -137,7 +138,7 @@ def response(resp): results = parse_search_query(json_resp['results']) elif search_type == 'images': - for item in json_resp['images']: + for item in json_resp.get('images', []): results.append( { 'template': 'images.html', @@ -152,7 +153,7 @@ def response(resp): # The results in the video category are most often links to pages that contain # a video and not to a video stream --> SearXNG can't use the video template. - for item in json_resp['videos']: + for item in json_resp.get('videos', []): metadata = [x for x in [item.get('description'), item.get('duration')] if x] results.append( { @@ -165,7 +166,7 @@ def response(resp): ) elif search_type == 'news': - for item in json_resp['news']: + for item in json_resp.get('news', []): metadata = [x for x in [item.get('source'), item.get('time')] if x] results.append( { |