160 """Parse results from Qwant-Lite"""
163 dom = lxml.html.fromstring(resp.text)
165 for item
in eval_xpath_list(dom,
'//section/article'):
166 if eval_xpath(item,
"./span[contains(@class, 'tooltip')]"):
171 'url': extract_text(eval_xpath(item,
"./span[contains(@class, 'url partner')]")),
172 'title': extract_text(eval_xpath(item,
'./h2/a')),
173 'content': extract_text(eval_xpath(item,
'./p')),
181 """Parse results from Qwant's API"""
187 search_results = loads(resp.text)
188 data = search_results.get(
'data', {})
191 if search_results.get(
'status') !=
'success':
192 error_code = data.get(
'error_code')
195 if search_results.get(
"data", {}).get(
"error_data", {}).get(
"captchaUrl")
is not None:
197 msg =
",".join(data.get(
'message', [
'unknown']))
201 raise_for_httperror(resp)
203 if qwant_categ ==
'web':
207 mainline = data.get(
'result', {}).get(
'items', {}).get(
'mainline', {})
212 mainline = data.get(
'result', {}).get(
'items', [])
214 {
'type': qwant_categ,
'items': mainline},
222 mainline_type = row.get(
'type',
'web')
223 if mainline_type != qwant_categ:
226 if mainline_type ==
'ads':
230 mainline_items = row.get(
'items', [])
231 for item
in mainline_items:
233 title = item.get(
'title',
None)
234 res_url = item.get(
'url',
None)
236 if mainline_type ==
'web':
237 content = item[
'desc']
246 elif mainline_type ==
'news':
248 pub_date = item[
'date']
249 if pub_date
is not None:
250 pub_date = datetime.fromtimestamp(pub_date)
251 news_media = item.get(
'media', [])
254 thumbnail = news_media[0].get(
'pict', {}).get(
'url',
None)
259 'publishedDate': pub_date,
260 'thumbnail': thumbnail,
264 elif mainline_type ==
'images':
265 thumbnail = item[
'thumbnail']
266 img_src = item[
'media']
271 'template':
'images.html',
272 'thumbnail_src': thumbnail,
274 'resolution': f
"{item['width']} x {item['height']}",
275 'img_format': item.get(
'thumb_type'),
279 elif mainline_type ==
'videos':
283 d, s, c = item.get(
'desc'), item.get(
'source'), item.get(
'channel')
286 content_parts.append(d)
288 content_parts.append(
"%s: %s " % (gettext(
"Source"), s))
290 content_parts.append(
"%s: %s " % (gettext(
"Channel"), c))
291 content =
' // '.join(content_parts)
292 length = item[
'duration']
293 if length
is not None:
294 length = timedelta(milliseconds=length)
295 pub_date = item[
'date']
296 if pub_date
is not None:
297 pub_date = datetime.fromtimestamp(pub_date)
298 thumbnail = item[
'thumbnail']
301 thumbnail = thumbnail.replace(
'https://s2.qwant.com',
'https://s1.qwant.com', 1)
307 'iframe_src': get_embeded_stream_url(res_url),
308 'publishedDate': pub_date,
309 'thumbnail': thumbnail,
310 'template':
'videos.html',
321 from searx
import network
325 resp = network.get(about[
'website'])
326 json_string = extr(resp.text,
'INITIAL_PROPS = ',
'</script>')
328 q_initial_props = loads(json_string)
329 q_locales = q_initial_props.get(
'locales')
332 for country, v
in q_locales.items():
333 for lang
in v[
'langs']:
334 _locale =
"{lang}_{country}".
format(lang=lang, country=country)
336 if qwant_categ ==
'news' and _locale.lower()
not in qwant_news_locales:
340 eng_tag_list.add(_locale)
342 for eng_tag
in eng_tag_list:
344 sxng_tag = region_tag(babel.Locale.parse(eng_tag, sep=
'_'))
345 except babel.UnknownLocaleError:
346 print(
"ERROR: can't determine babel locale of quant's locale %s" % eng_tag)
349 conflict = engine_traits.regions.get(sxng_tag)
351 if conflict != eng_tag:
352 print(
"CONFLICT: babel %s --> %s, %s" % (sxng_tag, conflict, eng_tag))
354 engine_traits.regions[sxng_tag] = eng_tag