From e29e861e2c4fe6848755d85da9a72533b5bedb68 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Mon, 25 May 2026 17:05:08 +0200 Subject: [PATCH] [fix] bing engines - geoblocking in China (#6134) In regions like China, the domain must be adjusted to avoid a redirect. - https://github.com/searxng/searxng/issues/5243 - https://github.com/searxng/searxng/pull/5324 - https://github.com/searxng/searxng/pull/6133 Suggested / tested by @hubutui in https://github.com/searxng/searxng/pull/6133#issuecomment-4534637069 Signed-off-by: Markus Heiser --- searx/engines/bing.py | 12 +++--------- searx/engines/bing_images.py | 6 ++---- searx/engines/bing_news.py | 6 ++---- searx/engines/bing_videos.py | 4 ++-- searx/settings.yml | 4 ++++ 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/searx/engines/bing.py b/searx/engines/bing.py index cae89d24f..10390a6d4 100644 --- a/searx/engines/bing.py +++ b/searx/engines/bing.py @@ -47,7 +47,7 @@ _safesearch_map: dict[int, str] = { } """Filter results. 0: None, 1: Moderate, 2: Strict""" -base_url = "https://www.bing.com/search" +base_url = "https://www.bing.com" """Bing-Web search URL""" @@ -93,7 +93,7 @@ def override_accept_language(params: "OnlineParams", engine_region: str | None) params["headers"]["Accept-Language"] = f"{engine_region},{lang};q=0.9" -def request(query: str, params: "OnlineParams") -> "OnlineParams": +def request(query: str, params: "OnlineParams"): """Assemble a Bing-Web request.""" engine_region = traits.get_region(params["searxng_locale"], traits.all_locale) @@ -109,13 +109,7 @@ def request(query: str, params: "OnlineParams") -> "OnlineParams": if locale_params: query_params.update(locale_params) - params["url"] = f"{base_url}?{urlencode(query_params)}" - - # in some regions where geoblocking is employed (e.g. China), - # www.bing.com redirects to the regional version of Bing - params["allow_redirects"] = True - - return params + params["url"] = f"{base_url}/search?{urlencode(query_params)}" def response(resp: "SXNG_Response") -> list[dict[str, t.Any]]: diff --git a/searx/engines/bing_images.py b/searx/engines/bing_images.py index a8439a414..078a18733 100644 --- a/searx/engines/bing_images.py +++ b/searx/engines/bing_images.py @@ -34,7 +34,7 @@ time_map = { "year": 60 * 24 * 365, } -base_url = "https://www.bing.com/images/async" +base_url = "https://www.bing.com" """Bing-Image search URL""" @@ -64,9 +64,7 @@ def request(query, params): if params["time_range"]: query_params["qft"] = "filterui:age-lt%s" % time_map[params["time_range"]] - params["url"] = base_url + "?" + urlencode(query_params) - - return params + params["url"] = base_url + "/images/async?" + urlencode(query_params) def response(resp): diff --git a/searx/engines/bing_news.py b/searx/engines/bing_news.py index 3c10b53d3..0e93af83e 100644 --- a/searx/engines/bing_news.py +++ b/searx/engines/bing_news.py @@ -44,7 +44,7 @@ time_map = { difference of *last day* and *last week* in the result list is just marginally. Bing does not have news range ``year`` / we use ``month`` instead.""" -base_url = "https://www.bing.com/news/infinitescrollajax" +base_url = "https://www.bing.com" """Bing (News) search URL""" @@ -74,9 +74,7 @@ def request(query, params): if params["time_range"]: query_params["qft"] = time_map.get(params["time_range"], 'interval="9"') - params["url"] = base_url + "?" + urlencode(query_params) - - return params + params["url"] = base_url + "/news/infinitescrollajax?" + urlencode(query_params) def response(resp): diff --git a/searx/engines/bing_videos.py b/searx/engines/bing_videos.py index 6169c5ec6..2ad53baeb 100644 --- a/searx/engines/bing_videos.py +++ b/searx/engines/bing_videos.py @@ -29,7 +29,7 @@ paging = True safesearch = True time_range_support = True -base_url = "https://www.bing.com/videos/asyncv2" +base_url = "https://www.bing.com" """Bing-Video search URL""" @@ -60,7 +60,7 @@ def request(query, params): query_params["form"] = "VRFLTR" query_params["qft"] = " filterui:videoage-lt%s" % time_map[params["time_range"]] - params["url"] = base_url + "?" + urlencode(query_params) + params["url"] = base_url + "/videos/asyncv2?" + urlencode(query_params) return params diff --git a/searx/settings.yml b/searx/settings.yml index e6f68c075..d0069ea05 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -531,18 +531,22 @@ engines: engine: bing shortcut: bi disabled: true + # base_url: https://cn.bing.com # for instances hosted in China - name: bing images engine: bing_images shortcut: bii + # base_url: https://cn.bing.com # for instances hosted in China - name: bing news engine: bing_news shortcut: bin + # base_url: https://cn.bing.com # for instances hosted in China - name: bing videos engine: bing_videos shortcut: biv + # base_url: https://cn.bing.com # for instances hosted in China - name: bitchute engine: bitchute