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.get('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