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

171
Visualizações
How To Select one of the same multiple elements in cheerio nodejs?

I'm trying to scrape links from a page, but the problem I'm facing right now is that i want to scrape href from anchor tag, but it has multiple tags with no class inside them.

It looks something like this

<div class="class1">
<a href="sample.com">Some random text</a>
<a href="example.com">Some random text</a>
</div>

Now I want to get example.com but when i try find(".class1").find("a").attr("href"); it returns me sample.com.

I want to do something like this to get example.com instead of sample.com find(".class1").find("a")[1].attr("href"); returns example.com

please someone help me with this. I'm a newbie to cheerio and cheerio's documentation is so much confusing to me.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can select the n-th <a> element using :

find(".class1").find("a:nth-child(4)").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