.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.bing_images Namespace Reference

Functions

 request (query, params)
 
 response (resp)
 

Variables

 logger = logging.getLogger()
 
EngineTraits traits
 
dict about
 
list categories = ['images', 'web']
 
bool paging = True
 
bool safesearch = True
 
bool time_range_support = True
 
str base_url = 'https://www.bing.com/images/async'
 
dict time_map
 

Detailed Description

Bing-Images: description see :py:obj:`searx.engines.bing`.

Function Documentation

◆ request()

searx.engines.bing_images.request ( query,
params )
Assemble a Bing-Image request.

Definition at line 52 of file bing_images.py.

52def request(query, params):
53 """Assemble a Bing-Image request."""
54
55 engine_region = traits.get_region(params['searxng_locale'], traits.all_locale) # type: ignore
56 engine_language = traits.get_language(params['searxng_locale'], 'en') # type: ignore
57 set_bing_cookies(params, engine_language, engine_region)
58
59 # build URL query
60 # - example: https://www.bing.com/images/async?q=foo&async=content&first=1&count=35
61 query_params = {
62 'q': query,
63 'async': '1',
64 # to simplify the page count lets use the default of 35 images per page
65 'first': (int(params.get('pageno', 1)) - 1) * 35 + 1,
66 'count': 35,
67 }
68
69 # time range
70 # - example: one year (525600 minutes) 'qft=+filterui:age-lt525600'
71
72 if params['time_range']:
73 query_params['qft'] = 'filterui:age-lt%s' % time_map[params['time_range']]
74
75 params['url'] = base_url + '?' + urlencode(query_params)
76
77 return params
78
79

◆ response()

searx.engines.bing_images.response ( resp)
Get response from Bing-Images

Definition at line 80 of file bing_images.py.

80def response(resp):
81 """Get response from Bing-Images"""
82
83 results = []
84 dom = html.fromstring(resp.text)
85
86 for result in dom.xpath('//ul[contains(@class, "dgControl_list")]/li'):
87
88 metadata = result.xpath('.//a[@class="iusc"]/@m')
89 if not metadata:
90 continue
91
92 metadata = json.loads(result.xpath('.//a[@class="iusc"]/@m')[0])
93 title = ' '.join(result.xpath('.//div[@class="infnmpt"]//a/text()')).strip()
94 img_format = ' '.join(result.xpath('.//div[@class="imgpt"]/div/span/text()')).strip().split(" ยท ")
95 source = ' '.join(result.xpath('.//div[@class="imgpt"]//div[@class="lnkw"]//a/text()')).strip()
96 results.append(
97 {
98 'template': 'images.html',
99 'url': metadata['purl'],
100 'thumbnail_src': metadata['turl'],
101 'img_src': metadata['murl'],
102 'content': metadata['desc'],
103 'title': title,
104 'source': source,
105 'resolution': img_format[0],
106 'img_format': img_format[1] if len(img_format) >= 2 else None,
107 }
108 )
109 return results

Variable Documentation

◆ about

dict searx.engines.bing_images.about
Initial value:
1= {
2 "website": 'https://www.bing.com/images',
3 "wikidata_id": 'Q182496',
4 "official_api_documentation": 'https://www.microsoft.com/en-us/bing/apis/bing-image-search-api',
5 "use_official_api": False,
6 "require_api_key": False,
7 "results": 'HTML',
8}

Definition at line 26 of file bing_images.py.

◆ base_url

str searx.engines.bing_images.base_url = 'https://www.bing.com/images/async'

Definition at line 41 of file bing_images.py.

◆ categories

list searx.engines.bing_images.categories = ['images', 'web']

Definition at line 36 of file bing_images.py.

◆ logger

searx.engines.bing_images.logger = logging.getLogger()

Definition at line 21 of file bing_images.py.

◆ paging

bool searx.engines.bing_images.paging = True

Definition at line 37 of file bing_images.py.

◆ safesearch

bool searx.engines.bing_images.safesearch = True

Definition at line 38 of file bing_images.py.

◆ time_map

dict searx.engines.bing_images.time_map
Initial value:
1= {
2 'day': 60 * 24,
3 'week': 60 * 24 * 7,
4 'month': 60 * 24 * 31,
5 'year': 60 * 24 * 365,
6}

Definition at line 44 of file bing_images.py.

◆ time_range_support

bool searx.engines.bing_images.time_range_support = True

Definition at line 39 of file bing_images.py.

◆ traits

EngineTraits searx.engines.bing_images.traits

Definition at line 23 of file bing_images.py.