mirror of
https://github.com/searxng/searxng.git
synced 2026-05-26 12:50:14 +02:00
[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 <markus.heiser@darmarit.de>
This commit is contained in:
@@ -47,7 +47,7 @@ _safesearch_map: dict[int, str] = {
|
|||||||
}
|
}
|
||||||
"""Filter results. 0: None, 1: Moderate, 2: Strict"""
|
"""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"""
|
"""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"
|
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."""
|
"""Assemble a Bing-Web request."""
|
||||||
|
|
||||||
engine_region = traits.get_region(params["searxng_locale"], traits.all_locale)
|
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:
|
if locale_params:
|
||||||
query_params.update(locale_params)
|
query_params.update(locale_params)
|
||||||
|
|
||||||
params["url"] = f"{base_url}?{urlencode(query_params)}"
|
params["url"] = f"{base_url}/search?{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
|
|
||||||
|
|
||||||
|
|
||||||
def response(resp: "SXNG_Response") -> list[dict[str, t.Any]]:
|
def response(resp: "SXNG_Response") -> list[dict[str, t.Any]]:
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ time_map = {
|
|||||||
"year": 60 * 24 * 365,
|
"year": 60 * 24 * 365,
|
||||||
}
|
}
|
||||||
|
|
||||||
base_url = "https://www.bing.com/images/async"
|
base_url = "https://www.bing.com"
|
||||||
"""Bing-Image search URL"""
|
"""Bing-Image search URL"""
|
||||||
|
|
||||||
|
|
||||||
@@ -64,9 +64,7 @@ def request(query, params):
|
|||||||
if params["time_range"]:
|
if params["time_range"]:
|
||||||
query_params["qft"] = "filterui:age-lt%s" % time_map[params["time_range"]]
|
query_params["qft"] = "filterui:age-lt%s" % time_map[params["time_range"]]
|
||||||
|
|
||||||
params["url"] = base_url + "?" + urlencode(query_params)
|
params["url"] = base_url + "/images/async?" + urlencode(query_params)
|
||||||
|
|
||||||
return params
|
|
||||||
|
|
||||||
|
|
||||||
def response(resp):
|
def response(resp):
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ time_map = {
|
|||||||
difference of *last day* and *last week* in the result list is just marginally.
|
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."""
|
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"""
|
"""Bing (News) search URL"""
|
||||||
|
|
||||||
|
|
||||||
@@ -74,9 +74,7 @@ def request(query, params):
|
|||||||
if params["time_range"]:
|
if params["time_range"]:
|
||||||
query_params["qft"] = time_map.get(params["time_range"], 'interval="9"')
|
query_params["qft"] = time_map.get(params["time_range"], 'interval="9"')
|
||||||
|
|
||||||
params["url"] = base_url + "?" + urlencode(query_params)
|
params["url"] = base_url + "/news/infinitescrollajax?" + urlencode(query_params)
|
||||||
|
|
||||||
return params
|
|
||||||
|
|
||||||
|
|
||||||
def response(resp):
|
def response(resp):
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ paging = True
|
|||||||
safesearch = True
|
safesearch = True
|
||||||
time_range_support = True
|
time_range_support = True
|
||||||
|
|
||||||
base_url = "https://www.bing.com/videos/asyncv2"
|
base_url = "https://www.bing.com"
|
||||||
"""Bing-Video search URL"""
|
"""Bing-Video search URL"""
|
||||||
|
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ def request(query, params):
|
|||||||
query_params["form"] = "VRFLTR"
|
query_params["form"] = "VRFLTR"
|
||||||
query_params["qft"] = " filterui:videoage-lt%s" % time_map[params["time_range"]]
|
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
|
return params
|
||||||
|
|
||||||
|
|||||||
@@ -531,18 +531,22 @@ engines:
|
|||||||
engine: bing
|
engine: bing
|
||||||
shortcut: bi
|
shortcut: bi
|
||||||
disabled: true
|
disabled: true
|
||||||
|
# base_url: https://cn.bing.com # for instances hosted in China
|
||||||
|
|
||||||
- name: bing images
|
- name: bing images
|
||||||
engine: bing_images
|
engine: bing_images
|
||||||
shortcut: bii
|
shortcut: bii
|
||||||
|
# base_url: https://cn.bing.com # for instances hosted in China
|
||||||
|
|
||||||
- name: bing news
|
- name: bing news
|
||||||
engine: bing_news
|
engine: bing_news
|
||||||
shortcut: bin
|
shortcut: bin
|
||||||
|
# base_url: https://cn.bing.com # for instances hosted in China
|
||||||
|
|
||||||
- name: bing videos
|
- name: bing videos
|
||||||
engine: bing_videos
|
engine: bing_videos
|
||||||
shortcut: biv
|
shortcut: biv
|
||||||
|
# base_url: https://cn.bing.com # for instances hosted in China
|
||||||
|
|
||||||
- name: bitchute
|
- name: bitchute
|
||||||
engine: bitchute
|
engine: bitchute
|
||||||
|
|||||||
Reference in New Issue
Block a user