I have this Apps Script / Cheerio function that successfully scrapes the data I want from the url. The site only displays 25 entries at this url. I can find additional entries on subsequent pages (by increasing the number at the end of the url to count=25, count=50, etc.). How can I loop this function so it scrapes multiple pages into one table?
function yahooSkImport() {
var url = 'https://hockey.fantasysports.yahoo.com/hockey/121356/players?status=ALL&eteam=ALL&fteam=NONE&pos=P&cut_type=33&stat1=S_S_2025&myteam=0&sort=PTS&sdir=1&count=0';
var response = UrlFetchApp.fetch(url);
var html = response.getContentText();
var $ = Cheerio.load(html);
var tableData = [];
$('table').find('tr').each(function(j, row) {
var cellData = [];
// Player Name
$(row).find('td:nth-of-type(3) > div > div > div:nth-of-type(2) > div > div > div > a').each(function(k, cell) {
cellData.push($(cell).text());
});
// Team - Pos
$(row).find('td:nth-of-type(3) > div > div > div:nth-of-type(2) > div > div > div > span[class="D-b"] > span').each(function(k, cell) {
cellData.push($(cell).text());
});
// % Ros
$(row).find('td:nth-of-type(10)').each(function(k, cell) {
cellData.push($(cell).text());
});
// Status
$(row).find('td:nth-of-type(3) > div > div > div:nth-of-type(2) > div > div > div > span > span[class="Pstart-sm"]').each(function(k, cell) {
cellData.push($(cell).text());
});
tableData.push(cellData);
});
//Logger.log(tableData);
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName('Sheet1');
sheet.clear();
const lastRow = sheet.getLastRow();
const range = sheet.getRange(lastRow+1, 1, tableData.length,tableData[0].length);
range.setValues(tableData);
};