summaryrefslogtreecommitdiff
path: root/searx/engines/duckduckgo.py
diff options
context:
space:
mode:
authorNicolas Dato <52720256+nicolasdato@users.noreply.github.com>2024-11-13 23:11:22 -0300
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-11-14 09:33:54 +0100
commitabd9b271bc1c4cc4dc1ee531944ce27c1e2734cc (patch)
tree4f4ee1db163a980a5cc1f6b5038f1c3ba841f03b /searx/engines/duckduckgo.py
parentdfaf5868e226b0540ed91b438dd2b4e3805680ca (diff)
downloadsearxng-abd9b271bc1c4cc4dc1ee531944ce27c1e2734cc.tar.gz
searxng-abd9b271bc1c4cc4dc1ee531944ce27c1e2734cc.zip
[fix] engine: duckduckgo - only uses first word of the search terms
during the revision in PR #3955 the query string was accidentally converted into a list of words, further the query must be quoted before POSTed in the ``data`` field, see ``urllib.parse.quote_plus`` [1] [1] https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote_plus Closed: #4009 Co-Authored-by: @return42
Diffstat (limited to 'searx/engines/duckduckgo.py')
-rw-r--r--searx/engines/duckduckgo.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/searx/engines/duckduckgo.py b/searx/engines/duckduckgo.py
index 3b73d1b6c..a7226043b 100644
--- a/searx/engines/duckduckgo.py
+++ b/searx/engines/duckduckgo.py
@@ -6,7 +6,7 @@ DuckDuckGo Lite
from typing import TYPE_CHECKING
import re
-from urllib.parse import urlencode
+from urllib.parse import urlencode, quote_plus
import json
import babel
import lxml.html
@@ -245,10 +245,12 @@ def request(query, params):
# Advanced search syntax ends in CAPTCHA
# https://duckduckgo.com/duckduckgo-help-pages/results/syntax/
- query = [
- x.removeprefix("site:").removeprefix("intitle:").removeprefix("inurl:").removeprefix("filetype:")
- for x in query.split()
- ]
+ query = " ".join(
+ [
+ x.removeprefix("site:").removeprefix("intitle:").removeprefix("inurl:").removeprefix("filetype:")
+ for x in query.split()
+ ]
+ )
eng_region = traits.get_region(params['searxng_locale'], traits.all_locale)
if eng_region == "wt-wt":
# https://html.duckduckgo.com/html sets an empty value for "all".
@@ -261,7 +263,7 @@ def request(query, params):
params['url'] = url
params['method'] = 'POST'
- params['data']['q'] = query
+ params['data']['q'] = quote_plus(query)
# The API is not documented, so we do some reverse engineering and emulate
# what https://html.duckduckgo.com/html does when you press "next Page" link