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

83
Visualizações
Extract url from a specific class using cheerio
 var result = [];
  for(var i =1; i <= 20; i++){

   var url = 'https://example.com/page/'
    var resp = UrlFetchApp.fetch(url, options).getContentText();
     var $ = Cheerio.load(resp);
var jobList = $(".views-field.views-field-title > a");
        for(let i = 0; i < jobList.length; i++) {
         //   console.log(jobList[i].getAttribute("href"))
   var jobUrl = 'https://example.com' + /href="(.+?)">/.exec(jobList[j])[1];
      var data = scrapeJobDetails(jobUrl);
      if(data != null){
        result.push(...data);
      }
    }
  }
  var sheet = ss.getSheetByName('Sheet1');
  sheet.getRange('A2:Z').clearContent();
  sheet.getRange(sheet.getDataRange().getLastRow() + 1, 1, result.length, result[0].length).setValues(result);
}

i dont know where am getting it wrong.i want to extract all urls in a class. below is class tag from the web page

    <td class="views-field views-field-title">
  <a href="xxxxxxx" class="cat-job-rate recruiter-colorbox-processed">
    xxxxxx
  </a><br>
  <span class="job-label">Organization:</span>
  xxxxx | <span class="job-label">xxxxxx:</span>
  xxxx | <span class="job-label">xxxx:</span> xxxxx
</td>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There are several things wrong with your code. I removed some for loops that were not needed and restructured your code to what I think you're trying to do. I'm assuming your response is loading correctly too. This code will collect your urls in an array then go through each url in your array to run your scrapeJobDetails function.

Make sure you are collecting the correct information before adding your google sheets code.

var result = [];
var url = 'https://example.com/page/';
var resp = UrlFetchApp.fetch(url, options).getContentText();
var $ = Cheerio.load(resp);
var jobList = $(".views-field.views-field-title > a");
var urls = jobList.map(function() {return $(this).attr('href');}).toArray();
// debug code - outputs the urls it collected
console.log(urls);
for (let i = 0; i < urls.length; i++) {
  var data = scrapeJobDetails(urls[i]);
  if (data != null) {
    result.push(...data);
  }
}
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