Grab Sitemap with GoogleSheet
function sitemap(url) {
let results = [];
if (!url) return;
const sitemap = UrlFetchApp.fetch(url, {
muteHttpExceptions: true,
method: "GET",
followRedirects: true
});
const document = sitemap.getContentText().split("<url>");
const docHead = document.splice(0, 1);
for (var i = 0; i < document.length; i++)
results.push(document[i].split("</loc>")[0].split("<loc>")[1]
);
results = results.filter(function (el) {
return el != null;
});
return results;
}