diff options
author | Alexandre Flament <alex@al-f.net> | 2022-01-02 22:00:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-02 22:00:55 +0100 |
commit | d83aa2b0d233606b0a037af9086ded656521fd2b (patch) | |
tree | 1a8f24ae4e9ff683e89ce10177ef1f5981f5fd38 /searx | |
parent | c2e4b95e8d68ac151d51fbcd3f0875f2aaa3640f (diff) | |
parent | dc4f1f705dbd2678755ccd59a30b7cffdc92865f (diff) | |
download | searxng-d83aa2b0d233606b0a037af9086ded656521fd2b.tar.gz searxng-d83aa2b0d233606b0a037af9086ded656521fd2b.zip |
Merge pull request #613 from return42/pylint-bing-images
[pylint] Bing (Images) engine
Diffstat (limited to 'searx')
-rw-r--r-- | searx/engines/bing_images.py | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/searx/engines/bing_images.py b/searx/engines/bing_images.py index 73b61b896..f07d07144 100644 --- a/searx/engines/bing_images.py +++ b/searx/engines/bing_images.py @@ -1,11 +1,13 @@ # SPDX-License-Identifier: AGPL-3.0-or-later -""" - Bing (Images) +# lint: pylint +"""Bing (Images) + """ +from json import loads from urllib.parse import urlencode + from lxml import html -from json import loads from searx.utils import match_language from searx.engines.bing import language_aliases @@ -77,31 +79,28 @@ def response(resp): # parse results for result in dom.xpath('//div[@class="imgpt"]'): - try: - img_format = result.xpath('./div[contains(@class, "img_info")]/span/text()')[0] - # Microsoft seems to experiment with this code so don't make the path too specific, - # just catch the text section for the first anchor in img_info assuming this to be - # the originating site. - source = result.xpath('./div[contains(@class, "img_info")]//a/text()')[0] - - m = loads(result.xpath('./a/@m')[0]) - - # strip 'Unicode private use area' highlighting, they render to Tux - # the Linux penguin and a standing diamond on my machine... - title = m.get('t', '').replace('\ue000', '').replace('\ue001', '') - results.append( - { - 'template': 'images.html', - 'url': m['purl'], - 'thumbnail_src': m['turl'], - 'img_src': m['murl'], - 'content': '', - 'title': title, - 'source': source, - 'img_format': img_format, - } - ) - except: - continue + img_format = result.xpath('./div[contains(@class, "img_info")]/span/text()')[0] + # Microsoft seems to experiment with this code so don't make the path too specific, + # just catch the text section for the first anchor in img_info assuming this to be + # the originating site. + source = result.xpath('./div[contains(@class, "img_info")]//a/text()')[0] + + m = loads(result.xpath('./a/@m')[0]) + + # strip 'Unicode private use area' highlighting, they render to Tux + # the Linux penguin and a standing diamond on my machine... + title = m.get('t', '').replace('\ue000', '').replace('\ue001', '') + results.append( + { + 'template': 'images.html', + 'url': m['purl'], + 'thumbnail_src': m['turl'], + 'img_src': m['murl'], + 'content': '', + 'title': title, + 'source': source, + 'img_format': img_format, + } + ) return results |