Answers for "Grab Sitemap with GoogleSheet"

0

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;

}
Posted by: Guest on July-16-2021

Browse Popular Code Answers by Language