Skip to content

Instantly share code, notes, and snippets.

@timlrx
Created April 21, 2023 02:52
Show Gist options
  • Save timlrx/da61fd1ecd54c568ef4e5aa24f82b8b9 to your computer and use it in GitHub Desktop.
Save timlrx/da61fd1ecd54c568ef4e5aa24f82b8b9 to your computer and use it in GitHub Desktop.
Extract url from sitemap from browser console
// Extract the URLs from the sitemap on the current page
const urls = Array.from(document.getElementsByTagName("url")).map(url => url.getElementsByTagName("loc")[0].textContent.trim());
// Function to convert an array to a CSV string
function arrayToCSV(arr) {
return arr.map(row => row.join(",")).join("\n");
}
// Convert the URLs to a CSV string and log it to the console
const csv = arrayToCSV([["URL"], ...urls.map(url => [url])]);
console.log(csv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment