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