155 """Parse results from Qwant-Lite"""
158 dom = lxml.html.fromstring(resp.text)
160 for item
in eval_xpath_list(dom,
'//section/article'):
161 if eval_xpath(item,
"./span[contains(@class, 'tooltip')]"):
166 'url': extract_text(eval_xpath(item,
"./span[contains(@class, 'url partner')]")),
167 'title': extract_text(eval_xpath(item,
'./h2/a')),
168 'content': extract_text(eval_xpath(item,
'./p')),
176 """Parse results from Qwant's API"""
182 search_results = loads(resp.text)
183 data = search_results.get(
'data', {})
186 if search_results.get(
'status') !=
'success':
187 error_code = data.get(
'error_code')
190 msg =
",".join(data.get(
'message', [
'unknown']))
194 raise_for_httperror(resp)
196 if qwant_categ ==
'web':
200 mainline = data.get(
'result', {}).get(
'items', {}).get(
'mainline', {})
205 mainline = data.get(
'result', {}).get(
'items', [])
207 {
'type': qwant_categ,
'items': mainline},
215 mainline_type = row.get(
'type',
'web')
216 if mainline_type != qwant_categ:
219 if mainline_type ==
'ads':
223 mainline_items = row.get(
'items', [])
224 for item
in mainline_items:
226 title = item.get(
'title',
None)
227 res_url = item.get(
'url',
None)
229 if mainline_type ==
'web':
230 content = item[
'desc']
239 elif mainline_type ==
'news':
241 pub_date = item[
'date']
242 if pub_date
is not None:
243 pub_date = datetime.fromtimestamp(pub_date)
244 news_media = item.get(
'media', [])
247 img_src = news_media[0].get(
'pict', {}).get(
'url',
None)
252 'publishedDate': pub_date,
257 elif mainline_type ==
'images':
258 thumbnail = item[
'thumbnail']
259 img_src = item[
'media']
264 'template':
'images.html',
265 'thumbnail_src': thumbnail,
267 'resolution': f
"{item['width']} x {item['height']}",
268 'img_format': item.get(
'thumb_type'),
272 elif mainline_type ==
'videos':
276 d, s, c = item.get(
'desc'), item.get(
'source'), item.get(
'channel')
279 content_parts.append(d)
281 content_parts.append(
"%s: %s " % (gettext(
"Source"), s))
283 content_parts.append(
"%s: %s " % (gettext(
"Channel"), c))
284 content =
' // '.join(content_parts)
285 length = item[
'duration']
286 if length
is not None:
287 length = timedelta(milliseconds=length)
288 pub_date = item[
'date']
289 if pub_date
is not None:
290 pub_date = datetime.fromtimestamp(pub_date)
291 thumbnail = item[
'thumbnail']
294 thumbnail = thumbnail.replace(
'https://s2.qwant.com',
'https://s1.qwant.com', 1)
300 'publishedDate': pub_date,
301 'thumbnail': thumbnail,
302 'template':
'videos.html',
313 from searx
import network
316 resp = network.get(about[
'website'])
318 text = text[text.find(
'INITIAL_PROPS') :]
319 text = text[text.find(
'{') : text.find(
'</script>')]
321 q_initial_props = loads(text)
322 q_locales = q_initial_props.get(
'locales')
325 for country, v
in q_locales.items():
326 for lang
in v[
'langs']:
327 _locale =
"{lang}_{country}".
format(lang=lang, country=country)
329 if qwant_categ ==
'news' and _locale.lower()
not in qwant_news_locales:
333 eng_tag_list.add(_locale)
335 for eng_tag
in eng_tag_list:
337 sxng_tag = region_tag(babel.Locale.parse(eng_tag, sep=
'_'))
338 except babel.UnknownLocaleError:
339 print(
"ERROR: can't determine babel locale of quant's locale %s" % eng_tag)
342 conflict = engine_traits.regions.get(sxng_tag)
344 if conflict != eng_tag:
345 print(
"CONFLICT: babel %s --> %s, %s" % (sxng_tag, conflict, eng_tag))
347 engine_traits.regions[sxng_tag] = eng_tag