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

272
Vistas
Cheerio js take all addresses that contain text only

I have the following code which takes me all the addresses.

I only need addresses that contain text.

Ex:

<a href="https://www...." target="_blank">Text...</a>

But the problem that there are addresses that contain an image, these addresses I would like to exclude them.

Ex:

<a href="http://www..." target="_blank"><img src="http://www." border="0" alt=""></a>

$("div#posts > div > div > div > div > table > tbody > tr:nth-child(2) > td:nth-child(2) > div:nth-child(3)").each((_idx, el) => {
     $(el).find('a').each((_idx, el) => {
         let u = $(el).attr('href')
         if(u.includes("http")) element.add(u);
      })
})

Can you give me a hand?

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

0

try selecting a that does not have img (or maybe any children, if there are other elements), with combination of :has and :not

$(el).find('a:not(:has(img))').each((_idx, el) => {
    let u = $(el).attr('href')
    if (u.includes("http")) element.add(u);
})
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use filter:

$('a').get().filter(a => $(a).text().match(/\w/)).map(a => $(a).attr('href'))
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