How to Extract Links from Websites using Sitemap in Sheets

Key Takeaways

  • ImportXML function allows users to extract data from any XML field on a website.
  • XML sitemaps provide a structured file that lists all pages on a website, aiding search engines in indexing content.
  • Common errors when using ImportXML include the #N/A error, which indicates issues retrieving data from the sitemap.
  • XPath queries must match the structure of the sitemap to avoid errors when importing links.

Are you tired of manually copying and pasting website links into your Google Sheets? Do you want a more efficient way to import website links into your spreadsheet?

Look no further than using a sitemap and ImportXML in Google Sheets.

I recently discovered this method and it has saved me a significant amount of time and effort. By utilizing a website’s sitemap and the ImportXML function in Google Sheets, I am able to easily import a list of website links into my spreadsheet.

This has been especially useful for tracking backlinks and conducting competitor research.

Table of Contents

What is a Sitemap?

As I begin to explain how to import website links using sitemap in Google Sheet using ImportXML for free, it’s important to first understand what a sitemap is.

In simple terms, a sitemap is a file that provides information about the pages, videos, and other files on a website, and the relationships between them. It helps search engines like Google to crawl and index all of a website’s content.

Sitemap
Example of Yoast SEO Plugin’s Sitemap

Sitemaps come in different formats, but the most common one is the XML sitemap. This type of sitemap is a structured file that lists all the pages on a website, along with additional information like their last modified date, priority, and frequency of change.

XML sitemaps are essential for any website owner who wants to improve their website’s visibility on search engines. By providing search engines with a clear roadmap of a website’s content, sitemaps can help to ensure that all pages are indexed and ranked appropriately.

I have also created a blog where I share how to extract all video links from YouTube Channel, as with YouTube you can run Import XML, we need the YouTube API v3. – Read How

Importing Website Links using Sitemap in Google Sheets

I will show you how to import website links using a sitemap in Google Sheets for free.

Step 1: Create a new Google Sheet and name it

The first step is to create a new Google Sheet and give it a name. This will be the sheet where you will import the website links from the sitemap.

To create a new Google Sheet, go to your Google Drive and click on the “New” button. Then, select “Google Sheets” from the drop-down menu. Once you have created the sheet, give it a name that is easy to remember.

or simply type sheets.new in your browser url field.

Step 2: Use ImportXML function to import data from Sitemap

The next step is to use the ImportXML function to import data from the sitemap. The ImportXML function is a powerful tool that allows you to extract data from any XML field on a website. To use the ImportXML function, you need to know the URL of the sitemap. Once you have the URL, you can use the following formula:

Extract Site URL from Sitemap

=IMPORTXML("URL","//*[local-name() ='url']/*[local-name() ='loc']")

This formula will import all the URLs from the sitemap into your Google Sheet.

So let’s test the output, we will use Yoast SEO website’s pages URL.

List of all Extracted URL in sheets from Sitemap

Voilà! And we’re done, we have successfully scraped all the links from Yoast SEO website.

Common Errors and Troubleshooting

Importing website links using sitemap in Google Sheet using ImportXML can sometimes encounter errors. Here are some of the common errors and their corresponding troubleshooting steps.

Your Clients Deserve Faster Sites. You Deserve Less Headaches.

You got into this to build websites, not babysit them.

But here you are. Plugin conflicts at 2am. Clients pinging about downtime. Security patches you forgot about.

I run dedicated VPS hosting for agencies. Blazing fast. 24/7 monitored. Plugin updates on autopilot. Hacked site? I clean it same day.

You focus on clients. I keep the servers running.

#N/A Error

One of the most common errors when importing website links using sitemap in Google Sheet is the #N/A error. This error appears when the ImportXML function is unable to retrieve the data from the sitemap.

To troubleshoot this error, you can try the following:

  • Check the URL of the sitemap. Make sure that it is correct and complete.
  • Verify that the sitemap is accessible and not blocked by the website’s robots.txt file.
  • Ensure that the syntax of the ImportXML function is correct.

Xpath Queries

Another issue that you might encounter when importing website links using sitemap in Google Sheet is with Xpath queries. Xpath is a query language used to extract data from XML documents, including sitemaps.

To troubleshoot Xpath errors, you may want to consider the following:

  • Verify that the Xpath query is correct and matches the structure of the sitemap.
  • Ensure that the Xpath query is enclosed in double quotes.
  • Check that the Xpath query does not contain any typos or syntax errors.

XML Files

Finally, you may encounter issues with the XML files themselves. This can happen if the sitemap is corrupted or if it contains invalid characters.

To troubleshoot XML file errors, you can try the following:

  • Verify that the sitemap is a valid XML file.
  • Check that the sitemap does not contain any invalid characters or syntax errors.
  • Try opening the sitemap in a different XML editor to see if the issue persists.

By following these troubleshooting steps, you can resolve common errors when importing website links using sitemap in Google Sheet using ImportXML.

I share what actually works in WordPress, SEO, and AI automation every week. Real numbers. Real experiments. No recycled advice.

Conclusion

In conclusion, using ImportXML in Google Sheets is a powerful tool to import website links and other data into your spreadsheet. By following the steps outlined in this article, you can easily scrape website links using a sitemap and import them into your Google Sheet for free.

However, it is important to keep in mind that ImportXML has its limitations. It may not work with all websites, and some websites may require more complex XPath queries to extract the desired data. Additionally, ImportXML may not be as reliable as other paid web scraping tools.

Frequently Asked Questions

What should I do if I encounter a #N/A error when using ImportXML?

The #N/A error typically indicates that the ImportXML function cannot retrieve data from the sitemap. To troubleshoot, check the sitemap URL for accuracy and ensure it's accessible without restrictions from the robots.txt file. Additionally, verify that your ImportXML syntax is correct. These steps can help resolve the issue and ensure successful data import.

What is the best way to structure my XPath query for extracting URLs?

To effectively extract URLs using XPath, ensure your query matches the sitemap's XML structure. The recommended XPath for importing URLs is '//* [local-name() ='url']/* [local-name() ='loc']'. This structure targets the correct elements in the XML, allowing for accurate data extraction into your Google Sheet.

What common mistakes should I avoid when using ImportXML with sitemaps?

Common mistakes include using incorrect XPath queries or failing to check the sitemap's accessibility. Ensure your XPath is correctly formatted and matches the sitemap's structure. Additionally, verify that the sitemap is not blocked by the site's robots.txt file, as this can prevent successful data retrieval.

How can I verify if my sitemap is a valid XML file?

To check if your sitemap is a valid XML file, open it in an XML editor or a web browser. Look for any syntax errors or invalid characters that could cause issues with the ImportXML function. Validating your sitemap ensures that you can successfully extract data without encountering errors.

What happens if the sitemap contains invalid characters?

If the sitemap contains invalid characters, the ImportXML function may fail to retrieve data, resulting in errors. It's crucial to ensure that the sitemap is clean and free from such characters. You can validate the sitemap in an XML editor to identify and correct these issues before attempting to import the data.

Last reviewed: April 16, 2026

About the Author

Photo of Aditya Sharma CMO & Marketing Head
CMO · POSIMYTH Innovations · 7 years experience

CMO at POSIMYTH Innovations (500K+ users). I do marketing, SEO, server management, AI automation, content, and YouTube. Everything I write here comes from real work and real experiments.

WordPressElementorn8nAIClaudeAutomationServer
Stop Managing Servers!
Start Managing Clients.

Your clients deserve servers that never flinch.
You deserve to never think about servers again.

Whether you need a bulletproof setup built from scratch or someone to take over what you already have  I handle the infrastructure so your agency can focus on what it bills for.

No downtime calls. No 3am panics. No excuses.

Explore Further