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

387
Vistas
Cheerio: find tag with multiple specific criteria easily and elegantly?

I'm trying to web scrape https://liquipedia.net/dota2/Admiral this page for all the <li> tags that are inside an <ul> tag that again is within a div with class mw-parser-output that has the title property. (I think that is what they're called in the HTML world? Like <tag property="...">).

What would be the most elegant, simple way to do this with Cheerio? I know I could do this with some for loops and stuff, but if there was a simple way to do this, my code would be a lot cleaner.

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

0

I'm sure glad Cheerio is like jQuery. A simple selector like this should do:

const li = $('div.mw-parser-output > ul > li[title]').toArray(); // Optionaly turn selected items into an array

Explanation of the CSS selector:

  1. div.mw-parser-output div makes sure the element is that. The dot signifies that the selector is a class.
  2. > Points to the immediate child
  3. ul Simple ul tag
  4. li[title] Any li tag, but it needs to have the title attribute.

Then we turn the result into an array so it become usable.
It's a simple as that.

You could also get an array of the text of each li element with the following:

const arrayOfLiTexts = li.map($el => $el.text());
about 4 years ago · Juan Pablo Isaza Denunciar

0

https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors

const elements = $('div[title].mw-parser-output ul li').toArray();
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