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

408
Visualizações
How to get the attribute value of a span tag with Cheerio in Javascript?

I'm trying to get a price change percent of a stock from Google Finance with Cheerio in Javascript. The following code didn't work, while the span tag shows the value in its "aria-label' attribute. Can anyone help fix what's wrong? Thank you for any advice!

function test() {
  var url = 'https://www.google.com/finance/quote/VZ:nyse';
  var res = UrlFetchApp.fetch(url, { muteHttpExceptions: true }).getContentText();
  var $ = Cheerio.load(res);

  // Succesfully retrieved the price.
  var price = $('div[class="YMlKec fxKbKc"]').first().text();
  console.log(price)

  // But couldn't figure out how to pull the price change percent.
  // The following code pulled out some results, but didn't include "Down by 3.55%", which is the price change that I'm looking for.  What's missing? 
  var changePercent = $('span[jsname="Fe7oBc"]').toArray().map(el => $(el).attr('aria-label'));
  console.log(changePercent)
}

enter image description here

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