81def response(resp):
82 """Get response from Bing-Video"""
83 results = []
84
85 if not resp.ok or not resp.text:
86 return results
87
88 dom = html.fromstring(resp.text)
89
90 for newsitem in eval_xpath_list(dom, '//div[contains(@class, "newsitem")]'):
91
92 link = eval_xpath_getindex(newsitem, './/a[@class="title"]', 0, None)
93 if link is None:
94 continue
95 url = link.attrib.get('href')
96 title = extract_text(link)
97 content = extract_text(eval_xpath(newsitem, './/div[@class="snippet"]'))
98
99 metadata = []
100 source = eval_xpath_getindex(newsitem, './/div[contains(@class, "source")]', 0, None)
101 if source is not None:
102 for item in (
103 eval_xpath_getindex(source, './/span[@aria-label]/@aria-label', 0, None),
104
105
106 link.attrib.get('data-author'),
107 ):
108 if item is not None:
109 t = extract_text(item)
110 if t and t.strip():
111 metadata.append(t.strip())
112 metadata = ' | '.join(metadata)
113
114 thumbnail = None
115 imagelink = eval_xpath_getindex(newsitem, './/a[@class="imagelink"]//img', 0, None)
116 if imagelink is not None:
117 thumbnail = imagelink.attrib.get('src')
118 if not thumbnail.startswith("https://www.bing.com"):
119 thumbnail = 'https://www.bing.com/' + thumbnail
120
121 results.append(
122 {
123 'url': url,
124 'title': title,
125 'content': content,
126 'thumbnail': thumbnail,
127 'metadata': metadata,
128 }
129 )
130
131 return results
132
133