60 """Assemble a Bing-News request."""
62 engine_region = traits.get_region(params[
'searxng_locale'], traits.all_locale)
63 engine_language = traits.get_language(params[
'searxng_locale'],
'en')
64 set_bing_cookies(params, engine_language, engine_region)
70 page = int(params.get(
'pageno', 1)) - 1
75 'first': page * 10 + 1,
78 'setlang': engine_region.split(
'-')[0],
79 'cc': engine_region.split(
'-')[-1],
82 if params[
'time_range']:
83 query_params[
'qft'] = time_map.get(params[
'time_range'],
'interval="9"')
85 params[
'url'] = base_url +
'?' + urlencode(query_params)
91 """Get response from Bing-Video"""
94 if not resp.ok
or not resp.text:
97 dom = html.fromstring(resp.text)
99 for newsitem
in eval_xpath_list(dom,
'//div[contains(@class, "newsitem")]'):
101 link = eval_xpath_getindex(newsitem,
'.//a[@class="title"]', 0,
None)
104 url = link.attrib.get(
'href')
105 title = extract_text(link)
106 content = extract_text(eval_xpath(newsitem,
'.//div[@class="snippet"]'))
109 source = eval_xpath_getindex(newsitem,
'.//div[contains(@class, "source")]', 0,
None)
110 if source
is not None:
112 eval_xpath_getindex(source,
'.//span[@aria-label]/@aria-label', 0,
None),
115 link.attrib.get(
'data-author'),
118 t = extract_text(item)
120 metadata.append(t.strip())
121 metadata =
' | '.join(metadata)
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
135 'thumbnail': thumbnail,
136 'metadata': metadata,