summaryrefslogtreecommitdiff
path: root/searx/engines/duckduckgo_extra.py
diff options
context:
space:
mode:
Diffstat (limited to 'searx/engines/duckduckgo_extra.py')
-rw-r--r--searx/engines/duckduckgo_extra.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/searx/engines/duckduckgo_extra.py b/searx/engines/duckduckgo_extra.py
index b30574d6c..6b0d4b98c 100644
--- a/searx/engines/duckduckgo_extra.py
+++ b/searx/engines/duckduckgo_extra.py
@@ -4,16 +4,15 @@ DuckDuckGo Extra (images, videos, news)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
+from __future__ import annotations
+
from datetime import datetime
from typing import TYPE_CHECKING
from urllib.parse import urlencode
from searx.utils import get_embeded_stream_url
from searx.engines.duckduckgo import fetch_traits # pylint: disable=unused-import
-from searx.engines.duckduckgo import (
- get_ddg_lang,
- get_vqd,
-)
+from searx.engines.duckduckgo import get_ddg_lang, get_vqd
from searx.enginelib.traits import EngineTraits
if TYPE_CHECKING:
@@ -48,15 +47,16 @@ search_path_map = {'images': 'i', 'videos': 'v', 'news': 'news'}
def request(query, params):
+ eng_region: str = traits.get_region(params['searxng_locale'], traits.all_locale) # type: ignore
# request needs a vqd argument
- vqd = get_vqd(query)
+ vqd = get_vqd(query, eng_region, force_request=True)
+
if not vqd:
# some search terms do not have results and therefore no vqd value
params['url'] = None
return params
- eng_region = traits.get_region(params['searxng_locale'], traits.all_locale)
eng_lang = get_ddg_lang(traits, params['searxng_locale'])
args = {
@@ -86,6 +86,12 @@ def request(query, params):
params['url'] = f'https://duckduckgo.com/{search_path_map[ddg_category]}.js?{urlencode(args)}'
+ # sending these two headers prevents rate limiting for the query
+ params['headers'] = {
+ 'Referer': 'https://duckduckgo.com/',
+ 'X-Requested-With': 'XMLHttpRequest',
+ }
+
return params