Import

Google Sheets IMPORTXML Function — Syntax, Examples & Tips

Learn how to use IMPORTXML in Google Sheets to extract data from web pages using XPath queries. Includes syntax, XPath examples, and scraping tips.

Syntax
=IMPORTXML(url, xpath_query)

What Is the IMPORTXML Function?

IMPORTXML pulls structured data from any publicly accessible web page or XML feed using XPath queries. While IMPORTHTML is limited to tables and lists, IMPORTXML can extract almost anything: headings, links, meta tags, prices, article titles, or any element you can target with an XPath expression. It is one of the most powerful scraping tools built into Google Sheets, requiring no code or external tools.

Syntax

=IMPORTXML(url, xpath_query)
ParameterDescription
urlThe full URL of the web page or XML document to import from.
xpath_queryAn XPath expression that specifies which elements to extract.

The results spill into adjacent cells starting from the formula cell, with each matched element occupying its own row.

Basic Examples

Extracting All H2 Headings from a Page

=IMPORTXML("https://en.wikipedia.org/wiki/Google_Sheets", "//h2")

This returns every <h2> heading on the Wikipedia page for Google Sheets, each in its own row. The //h2 XPath means "find all h2 elements anywhere in the document."

=IMPORTXML("https://example.com", "//a/@href")

Result: A list of every URL linked from the page. The @href targets the attribute rather than the element text.

Extracting Meta Description

=IMPORTXML("https://example.com", "//meta[@name='description']/@content")

This grabs the content of the meta description tag, which is useful for SEO audits across many pages.

Advanced Examples

Scraping Product Prices with Specific Class Names

Many e-commerce pages wrap prices in elements with predictable class names:

=IMPORTXML("https://example-store.com/product/123", "//span[@class='price']")

This extracts the text content of every <span> with the class "price." You may need to inspect the page source (right-click > Inspect) to find the correct element and class name for your target site.

Building an SEO Audit Sheet

You can audit multiple pages by placing URLs in column A and running IMPORTXML formulas across columns:

AB (Formula)C (Formula)
1URLTitleMeta Description
2https://example.com/page-1=IMPORTXML(A2,"//title")=IMPORTXML(A2,"//meta[@name='description']/@content")
3https://example.com/page-2=IMPORTXML(A3,"//title")=IMPORTXML(A3,"//meta[@name='description']/@content")

This gives you a quick overview of title tags and meta descriptions across your site. Add columns for h1 tags (//h1), canonical URLs (//link[@rel='canonical']/@href), or Open Graph data (//meta[@property='og:image']/@content).

Extracting Data from an RSS Feed

RSS feeds are XML, so IMPORTXML works perfectly:

=IMPORTXML("https://feeds.bbci.co.uk/news/rss.xml", "//item/title")

This returns the titles of the latest BBC News articles. Swap title for link or pubDate to get URLs or publication dates.

Common Mistakes

  • XPath returning nothing. Many modern websites render content via JavaScript after the page loads. IMPORTXML only sees the initial HTML response, not the JavaScript-rendered DOM. If a page loads data dynamically, IMPORTXML will not find it.
  • Hitting the import function limit. Google Sheets allows a maximum of 50 import function calls (IMPORTXML, IMPORTHTML, IMPORTDATA, IMPORTFEED combined) per spreadsheet. Plan your scraping accordingly and consider consolidating queries.
  • Unstable XPath selectors. Websites change their HTML structure regularly. An XPath query that works today may break next month if the site updates its layout. Use resilient selectors (target IDs and semantic elements rather than deeply nested positional paths) and check periodically.

SheetAI Tip

Don't want to memorize this syntax? With SheetAI, just type what you need in plain English and the formula is generated for you. Install SheetAI to try it free.

Skip the formula. Describe what you need.

SheetAI lets you type what you want in plain English and generates the perfect formula — no syntax to memorize.

Try SheetAI Free