Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
Filtre todas las instancias de una clase div usando cheerio

Novato de Cheerio/nodeJS aquí... guarda el vitriolo para los verdaderos villanos.

Estoy tratando de extraer el title (en este caso, "Alfacash") de la clase div exchange-card-small-logo > a > img. Podría haber varias instancias de esta clase div en el HTML. Estoy tratando de extraer el title de cada una de las instancias.

ingrese la descripción de la imagen aquí

console.log no se verá afectado en lo siguiente:

 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) })

Y ambos log devuelven 0:

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

También esto:

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

devoluciones:

 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] } } }

Este es el selector de CSS: #results > div > div.main-container.grid-flex > div:nth-child(1) > div.exchange-card-small-images > div.exchange-card-small-logo .

No puedo obtener la jerarquía correcta hasta esa clase div usando Cheerio. ¿Hay alguna forma de filtrar todas las instancias de esta clase sin recorrer todo el camino?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Los img están en el html, puedo verlos.

 $('.exchange-card-small-logo img').get().map(img => $(img).attr('title'))
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!