mirror of
https://github.com/searxng/searxng.git
synced 2026-09-12 17:26:05 +00:00
[fix] engine: bing images - remove market place argument mkt (#6699)
The ``mkt`` argument does no longer exists and the ``async`` argument has been renamed to ``mmasync``. For still unknown reasons (IP based?), some users had to observe that the title was missing [1]. I myself was not able to reproduce this error, however the evaluation of the title was additionally expanded by the attribute value of the ``<a title=".."`` element. Related: - [1] https://github.com/searxng/searxng/pull/6690#issuecomment-5636811572 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
committed by
Markus Heiser
parent
87bf8c86ed
commit
923a307454
@@ -62,8 +62,8 @@ def get_locale_params(engine_region: str | None) -> dict[str, str] | None:
|
||||
|
||||
The ``mkt`` parameter takes a full ``<language>-<country>`` code.
|
||||
|
||||
This function is shared with :py:mod:`searx.engines.bing_images`,
|
||||
:py:mod:`searx.engines.bing_news`, and :py:mod:`searx.engines.bing_videos`.
|
||||
This function is shared with :py:mod:`searx.engines.bing_news`, and
|
||||
:py:mod:`searx.engines.bing_videos`.
|
||||
"""
|
||||
|
||||
if not engine_region or engine_region == "clear":
|
||||
|
||||
@@ -6,10 +6,7 @@ from urllib.parse import urlencode
|
||||
|
||||
from lxml import html
|
||||
|
||||
from searx.engines.bing import ( # pylint: disable=unused-import
|
||||
fetch_traits,
|
||||
get_locale_params,
|
||||
)
|
||||
from searx.engines.bing import fetch_traits # pylint: disable=unused-import
|
||||
|
||||
# about
|
||||
about = {
|
||||
@@ -44,18 +41,21 @@ def request(query, params):
|
||||
engine_region = traits.get_region(params["searxng_locale"], traits.all_locale)
|
||||
|
||||
# build URL query
|
||||
# - example: https://www.bing.com/images/async?q=foo&async=1&first=1&count=35
|
||||
# - example: https://www.bing.com/images/async?q=foo&mmasync=1&first=1&count=35
|
||||
|
||||
query_params = {
|
||||
"q": query,
|
||||
"async": "1",
|
||||
"mmasync": "1",
|
||||
# to simplify the page count lets use the default of 35 images per page
|
||||
"first": (int(params.get("pageno", 1)) - 1) * 35 + 1,
|
||||
"count": 35,
|
||||
}
|
||||
|
||||
locale_params = get_locale_params(engine_region)
|
||||
if locale_params:
|
||||
query_params.update(locale_params)
|
||||
if engine_region and engine_region != "clear":
|
||||
lang, _, cc = engine_region.partition("-")
|
||||
query_params["setlang"] = lang
|
||||
if cc:
|
||||
query_params["cc"] = cc
|
||||
|
||||
# time range
|
||||
# - example: one year (525600 minutes) 'qft=filterui:age-lt525600'
|
||||
@@ -79,6 +79,9 @@ def response(resp):
|
||||
|
||||
metadata = json.loads(result.xpath('.//a[@class="iusc"]/@m')[0])
|
||||
title = " ".join(result.xpath('.//div[@class="infnmpt"]//a/text()')).strip()
|
||||
if not title:
|
||||
title = result.xpath('.//div[@class="infnmpt"]//a/@title')[0]
|
||||
|
||||
img_format = " ".join(result.xpath('.//div[@class="imgpt"]/div/span/text()')).strip().split(" · ")
|
||||
source = " ".join(result.xpath('.//div[@class="imgpt"]//div[@class="lnkw"]//a/text()')).strip()
|
||||
results.append(
|
||||
|
||||
Reference in New Issue
Block a user