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

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

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 Relatório

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