Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

81
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!