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

Functions

 request (query, params)
 response (resp)

Variables

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 40 of file bing_images.py.

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

◆ response()

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

Definition at line 68 of file bing_images.py.

68def response(resp):
69 """Get response from Bing-Images"""
70
71 results = []
72 dom = html.fromstring(resp.text)
73
74 for result in dom.xpath('//ul[contains(@class, "dgControl_list")]/li'):
75
76 metadata = result.xpath('.//a[@class="iusc"]/@m')
77 if not metadata:
78 continue
79
80 metadata = json.loads(result.xpath('.//a[@class="iusc"]/@m')[0])
81 title = ' '.join(result.xpath('.//div[@class="infnmpt"]//a/text()')).strip()
82 img_format = ' '.join(result.xpath('.//div[@class="imgpt"]/div/span/text()')).strip().split(" ยท ")
83 source = ' '.join(result.xpath('.//div[@class="imgpt"]//div[@class="lnkw"]//a/text()')).strip()
84 results.append(
85 {
86 'template': 'images.html',
87 'url': metadata['purl'],
88 'thumbnail_src': metadata['turl'],
89 'img_src': metadata['murl'],
90 'content': metadata.get('desc'),
91 'title': title,
92 'source': source,
93 'resolution': img_format[0],
94 'img_format': img_format[1] if len(img_format) >= 2 else None,
95 }
96 )
97 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 14 of file bing_images.py.

◆ base_url

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

Definition at line 29 of file bing_images.py.

◆ categories

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

Definition at line 24 of file bing_images.py.

◆ paging

bool searx.engines.bing_images.paging = True

Definition at line 25 of file bing_images.py.

◆ safesearch

bool searx.engines.bing_images.safesearch = True

Definition at line 26 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 32 of file bing_images.py.

◆ time_range_support

bool searx.engines.bing_images.time_range_support = True

Definition at line 27 of file bing_images.py.