Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda