161 """Parse results from Qwant-Lite"""
164 dom = lxml.html.fromstring(resp.text)
166 for item
in eval_xpath_list(dom,
'//section/article'):
167 if eval_xpath(item,
"./span[contains(@class, 'tooltip')]"):
172 'url': extract_text(eval_xpath(item,
"./span[contains(@class, 'url partner')]")),
173 'title': extract_text(eval_xpath(item,
'./h2/a')),
174 'content': extract_text(eval_xpath(item,
'./p')),
182 """Parse results from Qwant's API"""
188 search_results = loads(resp.text)
189 data = search_results.get(
'data', {})
192 if search_results.get(
'status') !=
'success':
193 error_code = data.get(
'error_code')
196 if search_results.get(
"data", {}).get(
"error_data", {}).get(
"captchaUrl")
is not None:
198 msg =
",".join(data.get(
'message', [
'unknown']))
202 raise_for_httperror(resp)
204 if qwant_categ ==
'web':
208 mainline = data.get(
'result', {}).get(
'items', {}).get(
'mainline', {})
213 mainline = data.get(
'result', {}).get(
'items', [])
215 {
'type': qwant_categ,
'items': mainline},
223 mainline_type = row.get(
'type',
'web')
224 if mainline_type != qwant_categ:
227 if mainline_type ==
'ads':
231 mainline_items = row.get(
'items', [])
232 for item
in mainline_items:
234 title = item.get(
'title',
None)
235 res_url = item.get(
'url',
None)
237 if mainline_type ==
'web':
238 content = item[
'desc']
247 elif mainline_type ==
'news':
249 pub_date = item[
'date']
250 if pub_date
is not None:
251 pub_date = datetime.fromtimestamp(pub_date)
252 news_media = item.get(
'media', [])
255 thumbnail = news_media[0].get(
'pict', {}).get(
'url',
None)
260 'publishedDate': pub_date,
261 'thumbnail': thumbnail,
265 elif mainline_type ==
'images':
266 thumbnail = item[
'thumbnail']
267 img_src = item[
'media']
272 'template':
'images.html',
273 'thumbnail_src': thumbnail,
275 'resolution': f
"{item['width']} x {item['height']}",
276 'img_format': item.get(
'thumb_type'),
280 elif mainline_type ==
'videos':
284 d, s, c = item.get(
'desc'), item.get(
'source'), item.get(
'channel')
287 content_parts.append(d)
289 content_parts.append(
"%s: %s " % (gettext(
"Source"), s))
291 content_parts.append(
"%s: %s " % (gettext(
"Channel"), c))
292 content =
' // '.join(content_parts)
293 length = item[
'duration']
294 if length
is not None:
295 length = timedelta(milliseconds=length)
296 pub_date = item[
'date']
297 if pub_date
is not None:
298 pub_date = datetime.fromtimestamp(pub_date)
299 thumbnail = item[
'thumbnail']
302 thumbnail = thumbnail.replace(
'https://s2.qwant.com',
'https://s1.qwant.com', 1)
308 'iframe_src': get_embeded_stream_url(res_url),
309 'publishedDate': pub_date,
310 'thumbnail': thumbnail,
311 'template':
'videos.html',
322 from searx
import network
326 resp = network.get(about[
'website'])
327 json_string = extr(resp.text,
'INITIAL_PROPS = ',
'</script>')
329 q_initial_props = loads(json_string)
330 q_locales = q_initial_props.get(
'locales')
333 for country, v
in q_locales.items():
334 for lang
in v[
'langs']:
335 _locale =
"{lang}_{country}".format(lang=lang, country=country)
337 if qwant_categ ==
'news' and _locale.lower()
not in qwant_news_locales:
341 eng_tag_list.add(_locale)
343 for eng_tag
in eng_tag_list:
345 sxng_tag = region_tag(babel.Locale.parse(eng_tag, sep=
'_'))
346 except babel.UnknownLocaleError:
347 print(
"ERROR: can't determine babel locale of quant's locale %s" % eng_tag)
350 conflict = engine_traits.regions.get(sxng_tag)
352 if conflict != eng_tag:
353 print(
"CONFLICT: babel %s --> %s, %s" % (sxng_tag, conflict, eng_tag))
355 engine_traits.regions[sxng_tag] = eng_tag