diff options
| author | Zhijie He <hezhijie0327@hotmail.com> | 2025-01-25 18:59:10 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-25 11:59:10 +0100 |
| commit | f3f13519ff8bad181ddb1e749a3e57dfd92f003c (patch) | |
| tree | d328039060200be17f3b3f61cb5607b288afde43 /searx/autocomplete.py | |
| parent | 04a6ab12fb6d7ec300df515831f13b228e1c5625 (diff) | |
[feat] autocompletion: add baidu search autocompleter (#4227)
Diffstat (limited to 'searx/autocomplete.py')
| -rw-r--r-- | searx/autocomplete.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/searx/autocomplete.py b/searx/autocomplete.py index 09589cf1f..206589c67 100644 --- a/searx/autocomplete.py +++ b/searx/autocomplete.py @@ -36,6 +36,21 @@ def post(*args, **kwargs): return http_post(*args, **kwargs) +def baidu(query, _lang): + # baidu search autocompleter + base_url = "https://www.baidu.com/sugrec?" + response = get(base_url + urlencode({'ie': 'utf-8', 'json': 1, 'prod': 'pc', 'wd': query})) + + results = [] + + if response.ok: + data = response.json() + if 'g' in data: + for item in data['g']: + results.append(item['q']) + return results + + def brave(query, _lang): # brave search autocompleter url = 'https://search.brave.com/api/suggest?' @@ -238,6 +253,7 @@ def yandex(query, _lang): backends = { + 'baidu': baidu, 'dbpedia': dbpedia, 'duckduckgo': duckduckgo, 'google': google_complete, |