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

199
Visualizações
Puppeteer - Looping through multiple elements with identical class names

I'm new to scraping. I'm trying to scrape the individual song links and stuff at this page https://www.ultimate-guitar.com/search.php?search_type=title&value=jimi%20hendrix%20little%20wing

There are many <div class = '_3uKbA'> elements and each one holds data for that particular song / version of the song. I can get these just fine. The issue comes from attempting to return the class names of the element which holds the star rating.

  1. The star rating element should return 5 class names, each one representing a blank star, a half star, or a full star UNLESS #2 happens.

The code below seems to only return one class name, and sometimes two, but never all 5 classes which is what I need to determine the rating (curse UG for not having a number on there...)

  1. The song has no star rating

(I think) With the way I'm looping, if the main div does not contain the star rating element, it searches the next available element. I want it to return something else instead if the particular main div doesn't have the star rating element.

Ideally, I'm looping through each individual main div and getting class names if it exists, and something else if it doesn't.

This is as close as I've been able to get and can't seem to come up with anything else.

const mainDiv = await page.$$('div._3uKbA');
const mainDivLength = await page.$$eval('div._3uKbA', el => el.length);
const divObj = [];
        
  for (let i = 3; i < mainDivLength; i++) {
    const divData = {
      name: await page.evaluate(el => el.textContent, (await page.$$('div._3uKbA a._3DU-x'))[i]),
      link: await page.evaluate(el => el.href, (await page.$$('div._3uKbA a._3DU-x'))[i]),
      stars: await page.evaluate(el => el.className, (await page.$$('div._3uKbA div._1cxy0 span'))[i]),
    }
    divObj.push(divData);
  }
    console.log(divObj);

about 4 years ago · Juan Pablo Isaza
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