IMPORTXML in Google Sheets: Syntax, XPath Examples, Fixes
By the Vurge team ·

In this article
IMPORTXML pulls data from a web page into Google Sheets using an XPath query: =IMPORTXML("https://example.com", "//h1") returns the page’s H1. It works on static HTML pages, XML feeds and sitemaps. It fails on content rendered by JavaScript and slows down once a sheet has hundreds of import formulas.
Below: the syntax, a set of XPath queries you can copy, every common error with its fix, and the point where it makes sense to stop fighting XPath.
How to use IMPORTXML, step by step
- Put the page URL in a cell, say A2, including
https://. - Open the page in Chrome, right-click the data you want and choose Inspect.
- Find the element’s tag and attributes (for example
<span class="price">). - Write the XPath for it, like
//span[@class='price']. - Enter
=IMPORTXML(A2, "//span[@class='price']")in B2. - Check the result against the page, then fill the formula down for other URLs.
The full syntax:
=IMPORTXML(url, xpath_query, [locale])
url: the page address, in quotes or as a cell reference. Include the protocol.xpath_query: the XPath, in quotes or a cell reference.locale(optional): a language and region code such as"en_US"or"de_DE". It controls how numbers and dates are parsed. Leave it out unless you’re scraping, say, a German site where1.299,00should become a number.
Photo by Zayed Hossain on Pexels
XPath examples you can copy
These cover maybe 80% of what people use IMPORTXML for. Swap A2 for your URL cell.
| What you want | Formula |
|---|---|
| Page title | =IMPORTXML(A2, "//title") |
| Meta description | =IMPORTXML(A2, "//meta[@name='description']/@content") |
| All H2 headings | =IMPORTXML(A2, "//h2") |
| First H1 only | =INDEX(IMPORTXML(A2, "//h1"), 1) |
| All link URLs | =IMPORTXML(A2, "//a/@href") |
| Canonical URL | =IMPORTXML(A2, "//link[@rel='canonical']/@href") |
| Element by exact class | =IMPORTXML(A2, "//div[@class='price']") |
| Element whose class contains a word | =IMPORTXML(A2, "//*[contains(@class,'price')]") |
| Element by ID | =IMPORTXML(A2, "//*[@id='main-title']") |
| URLs from an XML sitemap | =IMPORTXML(A2, "//*[local-name()='loc']") |
A few notes that save time.
Quotes trip people up more than XPath does. The formula wraps the query in double quotes, so use single quotes inside it. "//meta[@name="description"]" breaks; "//meta[@name='description']" works.
contains() is your friend. Modern sites stack classes like class="price price--sale text-lg", and [@class='price'] won’t match that. contains(@class,'price') will, though it may also match price-label, so check results.
The sitemap trick with local-name() exists because sitemaps use an XML namespace, and plain //loc often returns nothing.
When a query returns several values, they spill down the column. Wrap it in INDEX(..., 1) to keep only the first, or TEXTJOIN(", ", TRUE, IMPORTXML(...)) to put them in one cell.
Common IMPORTXML errors and how to fix them
“Imported content is empty” (#N/A)
The request worked but your XPath matched nothing. Three usual causes:
The data is loaded by JavaScript. Right-click the page, choose View Page Source (not Inspect), and search for the text you want. If it isn’t in the source, IMPORTXML can’t see it. No XPath will fix that.
Your XPath came from DevTools. Chrome’s “Copy XPath” gives you a path through the rendered DOM, often with things like /tbody that browsers insert and the raw HTML doesn’t have. Write a shorter query based on a class or ID instead of the full path.
A typo in the class name, or the class only matches with contains().
“Could not fetch url” (#N/A)
Sheets couldn’t load the page at all. Check that the URL has https://, opens in an incognito window, and isn’t behind a login. Many sites also block Google’s fetcher (you’ll get this on plenty of large retail and social sites). If the site blocks it, there’s no formula-side fix.
“Resource at url not found”
The page returned a 404 or similar. Often a trailing slash or redirect issue. Copy the final URL from your browser’s address bar after the page loads.
“Result too large”
Your query returns too much data, like //div on a big page. Narrow it to a specific class or ID.
“Loading…” forever, or “Loading data may take a while because of the large number of requests”
You’ve hit Google’s import quota. Google says the document creator has strict limits, counted across all their documents. Reduce the number of IMPORTXML formulas, and once you have the data, copy and paste as values (Ctrl+Shift+V) so the cells stop re-fetching.
Error about volatile functions
Import functions can’t reference NOW(), RAND() or RANDBETWEEN(), directly or indirectly. People try A2&"?"&RAND() to force a refresh. It doesn’t work.
Limits worth knowing before you build on it
Refresh is about hourly while the file is open, and you can’t schedule it. Reopening the sheet doesn’t trigger a fetch. Editing the formula does.
There’s no published per-sheet number for the quota. In practice, a sheet with a few dozen formulas is fine and a sheet with 500 starts stalling. Your mileage will vary with page size.
It needs a desktop browser to authorize external fetches; Google’s help notes mobile access can show a prompt to use a desktop browser.
And the big one: every website needs its own XPath. If column A has 200 URLs on one store’s template, one XPath works for all of them. If column A has 200 different company homepages, you need up to 200 different queries, and “the company’s pricing model” may not live in any single element anyway.
When to switch to an AI add-on
IMPORTXML is the right tool for SEO audits (titles, meta descriptions, canonicals), sitemaps and simple static pages. Use it. It’s free.
Switch when one of these is true: the pages are JavaScript-heavy, the URLs come from many different sites, or the information you want is a judgment (“what does this company sell?”) rather than a single element.
That’s the gap Vurge fills. URLs go in a column, you open the sidebar from Extensions, write a prompt like “find the price of the cheapest plan” or “list the founders,” and click Scrape. Answers are written next to each URL, with no XPath to maintain. It reads public pages only, it has no free plan (Starter is $20/month for 80 requests, see pricing), and it lives only in Google Sheets. For a list of 150 SaaS websites, though, it replaces an afternoon of XPath. Try Vurge on a column you’ve been struggling with.
For tables and lists specifically, IMPORTHTML is simpler than IMPORTXML. And if you’re scraping websites into Sheets more broadly, our guide on how to scrape data from a website into Google Sheets compares every method.
Bottom line
Learn the ten XPath patterns above, use single quotes, and check View Page Source before blaming your query. That handles most static pages. When the errors are about JavaScript, blocking or 200 different site layouts, no formula tweak will fix them. That’s when to start with Vurge or another tool built for the job, like the ones in our data analysis use case.
Scrape any website into Google Sheets
Write a prompt, click Scrape, get structured data. Plans from $20/month.


