Sitemaps are like treasure maps for websites—they list all the pages search engines should crawl. But extracting those links manually can be a headache. What if you could grab them instantly with a single click? Enter the JavaScript bookmarklet, a tiny script that turns your browser into a sitemap link extractor. Let’s dive in!
How to Use the Bookmarklet
There are two easy ways to set this up:
Method 1: Save via Browser Menu
- Copy the JavaScript code below (it’s a single line, so select all!).
- Create a new bookmark in Chrome (click the star icon next to the address bar).
- Name it something like “Extract Sitemap Links” and paste the code into the URL field.
- Goto any Sitemap URL and Click on it, It will shows the Sitemap links in New tab
Method 2: Drag the Bookmarklet to Bookmark Bar
- Drag and drop this link “Extract Sitemap Links in Chrome” JS bookmarklet to your browser bookmark bar.
Here’s the code to copy: JavaScriptCopy
javascript:(function(){function extractLinksFromSitemap(){let links=[];const locElements=document.getElementsByTagName('loc');links=links.concat(Array.from(locElements).map(el=>el.textContent.trim()));const sitemapTable=document.querySelector("#sitemap");if(sitemapTable){const anchorElements=sitemapTable.querySelectorAll("a");links=links.concat(Array.from(anchorElements).map(a=>a.href.trim()));}let htmlContent='<html><head><title>Sitemap Links</title><style>ul{list-style-type:none}li{margin-bottom:5px}</style></head><body><h1>Sitemap Links</h1><p>Total Links: '+links.length+'</p><button id="downloadCsv">Download as CSV</button> <button id="copyUrls">Copy URLs</button><ul>';links.forEach((link,index)=>{htmlContent+='<li>'+index+1+'. <a href="'+link+'" target="_blank">'+link+'</a></li>'});htmlContent+='</ul></body></html>';const newWindow=window.open('','_blank');newWindow.document.write(htmlContent);newWindow.document.close();newWindow.document.getElementById('downloadCsv').addEventListener('click',function(){let csvContent='URL\n'+links.join('\n');const blob=new Blob([csvContent],{type:'text/csv;charset=utf-8;'});const url=URL.createObjectURL(blob);const a=newWindow.document.createElement('a');a.href=url;a.download='sitemap_links.csv';newWindow.document.body.appendChild(a);a.click();newWindow.document.body.removeChild(a);URL.revokeObjectURL(url);});newWindow.document.getElementById('copyUrls').addEventListener('click',function(){const textArea=newWindow.document.createElement('textarea');textArea.value=links.join('\n');newWindow.document.body.appendChild(textArea);textArea.select();newWindow.document.execCommand('copy');newWindow.document.body.removeChild(textArea);alert('URLs copied to clipboard!');});}extractLinksFromSitemap();})();
How It Works
Once you’ve saved the bookmarklet:
- Visit any sitemap page (like
example.com/sitemap.xml
orexample.com/sitemap
). - Click the bookmarklet.
- A new window opens with:
- All extracted links listed.
- A Download as CSV button to save them as a file.
- A Copy URLs button to copy all links to your clipboard.
What’s happening behind the scenes?
- The script scans the page for
<loc>
tags (common in XML sitemaps) and anchor links inside a table (for HTML sitemaps). - It organizes the links into a user-friendly list and adds buttons for easy exporting.
Why This Bookmarklet Rocks
- Speed: No need to manually copy-paste links.
- Flexibility: Works on XML or HTML sitemaps.
- Export Options: Save as CSV or copy directly to share.
Conclusion
This bookmarklet is a game-changer for anyone working with sitemaps—SEO specialists, developers, or content managers. With just one click, you can extract, view, and export links effortlessly. Bookmark it today and say goodbye to tedious sitemap scraping!