Arthur Camberlein >> SEO & Data articles >> How to fetch & extract XML sitemaps URL in a Google Spreadsheet?

How to fetch & extract XML sitemaps URL in a Google Spreadsheet?

Written by Arthur Camberlein | Published on & updated on

There are several solutions to fetch the list of URLs from an XML sitemap directly in a Google Spreadsheet. My favorite one uses the IMPORTXML function with xPath.

How to extract all URLs from an XML sitemap with the IMPORTXML function?

If you are eager to get the function, here it is:

=IMPORTXML("https://arthur.camberlein.com/sitemap_blogs_1.xml", "//*[local-name() ='url']/*[local-name() ='loc']")

Google Spreadsheet used to fetch URLs from the XML sitemap

The step-by-step process would be:

  1. Open a new Google Spreadsheet
  2. Define a cell with your XML sitemap URL (in my case A1 = https://arthur.camberlein.com/sitemap_blogs_1.xml)
  3. Insert the following formula into another cell: =IMPORTXML(A1, "//*[local-name() ='url']/*[local-name() ='loc']")
  4. Make sure there is nothing below the cell containing the formula, or you'll get an error
  5. Voilà

This solution can be copied from tab to tab, or even between files, as you will only need to change the content of one cell (A1 in this case).

A quick explanation of the formula:

  • The IMPORTXML function works with xPath from a URL
  • A1 is the cell with the URL (here the XML sitemap URL)
  • The xPath tracks any URLs inside loc tags and extracts them using [local-name() ='loc']

Note: This article covers Google Spreadsheet as an all-in-one solution.

Back to blog

Learn more with the article FAQ

How to fetch & extract XML sitemaps URL in a Google Spreadsheet? - FAQs

What is the `=IMPORTXML()` fucntion?

Imports data from any of various structured data types including XML, HTML, CSV, TSV, and RSS and ATOM XML feeds.

What is an XML sitemap?

XML sitemaps are an easy way for webmasters to inform search engines about pages on their sites that are available for crawling. XML sitemaps can be declared to Webmaster Tools to Google, Bing and others.

Why using `IMPORTXML` for sitemaps?

Why using `IMPORTXML` to list and get unique URLs from your sitemap? To be fast, to 10x your productivity!

Blog post taggued in: Automation, SEO, Tips

Written by