Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
Filter out all instances of a div class using cheerio

Cheerio / nodeJS newbie here... save the vitriol for the real villains.

I am trying to extract the title (in this instance "Alfacash") from div class exchange-card-small-logo > a > img. There could be several instances of this div class in the HTML. I am trying to extract the title from each of the instances.

enter image description here

console.log won't get hit in the following:

axios.get("https://cryptoradar.co/exchanges")
    .then(response => {
        const html = response.data
        const $ = cheerio.load(html)

        $('.exchange-card-small-logo', html).each(function () {
            console.log($(this).length)
        })

And both of these log return 0:

const elems = $('.exchange-card-small-logo', html);
console.log(elems.length);
console.log(elems.toArray().length);

Also, this:

const elems = $('.exchange-card-small-logo', html);
console.log(elems);

returns:

LoadedCheerio {
  length: 0,
  options: { xml: false, decodeEntities: true },
  _root: <ref *1> LoadedCheerio {
    '0': Node {
      type: 'root',
      name: 'root',
      parent: null,
      prev: null,
      next: null,
      children: [Array],
      'x-mode': 'no-quirks'
    },
    length: 1,
    options: { xml: false, decodeEntities: true },
    _root: [Circular *1]
  },
  prevObject: LoadedCheerio {
    '0': Node {
      type: 'root',
      name: 'root',
      parent: null,
      prev: null,
      next: null,
      children: [Array]
    },
    length: 1,
    options: { xml: false, decodeEntities: true },
    _root: <ref *1> LoadedCheerio {
      '0': [Node],
      length: 1,
      options: [Object],
      _root: [Circular *1]
    },
    prevObject: LoadedCheerio {
      length: 0,
      options: [Object],
      _root: [LoadedCheerio]
    }
  }
}

This is the CSS selector: #results > div > div.main-container.grid-flex > div:nth-child(1) > div.exchange-card-small-images > div.exchange-card-small-logo.

I can't get the hierarchy right all the way down to that div class using cheerio. Is there a way to filter out all instances of this class without traversing all the path?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The imgs are there in the html, I can see them.

$('.exchange-card-small-logo img').get().map(img => $(img).attr('title'))
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda