Skip to content

@mhawksey /gist:4475786
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Google Apps Script function to return a sitemap.xml to Google Sheets (Spreadsheets)
function getSitemapData(url) {
try {
var options =
{
"method" : "get"
};
var response = UrlFetchApp.fetch(url, options);
if (response.getResponseCode() == 200) {
var output = [];
var row = [];
var responseStr = response.getContentText();
var XMLdoc = Xml.parse(responseStr); // parse xml
var urlset = XMLdoc.urlset;
var urls = urlset.getElements("url");
for (var i = 0; i < urls.length; i++) {
var el = urls[i].getElements();
if (i == 0){
for (j in el){
row.push(el[j].getName().getLocalName());
}
output.push(row);
var row = [];
}
for (j in el){
row.push(el[j].getText());
}
output.push(row);
var row = [];
}
return output;
}
} catch(e) {
throw e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.