Skip to content
Home

/

Glossary

/

Data

/

IMPORTXML

Data

7 min read

Also: =IMPORTXML, IMPORTXML function, Google Sheets IMPORTXML, ImportXML formula, IMPORTXML XPath, importxml google sheets

IMPORTXML

Quick answer

IMPORTXML is a Google Sheets function, =IMPORTXML(url, xpath_query), that downloads a page's raw HTML or XML and returns the nodes matching an XPath query. It cannot run JavaScript or log in, so when it shows an error, start with the "Could not fetch url" fix.

IMPORTXML is a Google Sheets function that fetches a URL from Google's servers and returns whatever an XPath query selects from the page, such as titles, prices or links. It reads only the raw HTML, so it cannot see content that JavaScript adds after the page loads.

Last verified

What people do with IMPORTXML

Key facts

Made byGoogle (a built-in Google Sheets function)
SyntaxIMPORTXML(url, xpath_query, [locale])
AcceptsXML, HTML, CSV, TSV, RSS and Atom XML feeds
Query languageXPath, run against the raw HTML the server returns (no JavaScript is executed)
RefreshGoogle checks the source for updates hourly while the spreadsheet is open
Where it runsOn Google's servers, not in your browser, so it cannot use your cookies or logins

What is IMPORTXML?

IMPORTXML is a built-in Google Sheets function that downloads a web page or XML document and pulls values out of it with an XPath query. Type =IMPORTXML("https://example.com", "//h1") into a cell and Sheets fills it with the text of every <h1> on that page. Because it needs no code, no add-on and no API key, it is usually the first scraping tool people try, and the first one they hit the limits of.

Google documents the function in the Google Docs Editors Help center. Its full signature is IMPORTXML(url, xpath_query, [locale]):

  • url: the page to fetch, including the protocol (https://). It must be in quotes or come from a cell reference.
  • xpath_query: an XPath 1.0 expression run against the document, for example //a/@href for every link or //span[@class='price'] for elements with that exact class.
  • locale (optional): a language and region code such as en_US, used when parsing numbers and dates. If omitted, the spreadsheet's locale is used.
  • When the query matches several nodes, the results spill down a column. When a node has children, they can spill across columns as well.

    How IMPORTXML actually fetches a page

    The request does not come from your computer. Google's servers fetch the URL, parse the response and send the matched values back to your sheet. That has three consequences that explain most of the confusion around the function:

  • No JavaScript runs. IMPORTXML sees the HTML the server sent, not the page you see in Chrome after scripts have run. If a product price or a table is rendered client-side, it does not exist as far as IMPORTXML is concerned.
  • No logins or cookies. The request carries none of your sessions, so anything behind a sign-in is invisible.
  • The site sees Google, not you. Many sites rate-limit or block requests from data-center IP ranges, and some block Google's fetcher specifically. A page that loads fine in your browser can still fail in Sheets.
  • Google's help center says import functions check the source for updates hourly while the document is open. Reopening the sheet or pressing refresh does not force a new fetch; deleting and re-entering the formula does. That makes IMPORTXML a poor fit for anything that needs minute-by-minute freshness.

    What people use IMPORTXML for

  • Pulling page titles, meta descriptions and H1s from a list of URLs for an SEO audit.
  • Tracking a price or stock figure on a static, server-rendered page.
  • Reading an RSS or Atom feed into a sheet (IMPORTFEED is the dedicated alternative).
  • Collecting every link on a page with //a/@href.
  • Grabbing a single value, like an exchange rate or a version number, to use in other formulas.
  • If the data you want is in a plain HTML <table> or <ul>, IMPORTHTML is simpler because it needs no XPath.

    Common IMPORTXML errors

  • Could not fetch url. Google's fetcher got no usable response: the site blocked it, returned an error, required a login, or the URL is malformed. Our guide to the Could not fetch url error walks through each cause.
  • Imported content is empty. The fetch worked but the XPath matched nothing. The most common reason is that the content is rendered by JavaScript, so it is not in the raw HTML. The second is an XPath copied from Chrome DevTools that depends on the rendered DOM, such as a tbody the browser inserted.
  • Resource at url contents exceeded maximum size. The page is larger than Sheets will import. Point at a smaller page or a narrower resource.
  • Result too large. The query returns too much; Google's help center suggests narrowing the XPath so it returns less.
  • Loading... that never finishes, or a warning that traffic is too high. Too many import functions across your spreadsheets are generating requests. Google recommends reducing the number of import functions you use.
  • Before blaming the formula, test the expression against the page's raw HTML. The XPath tester can load a URL the same way a server-side fetcher does and show which nodes match.

    IMPORTXML and automation

    IMPORTXML is a good tool for a handful of static pages and a poor one for anything else. It cannot click, paginate, sign in, wait for JavaScript, or run on a schedule you control, and it fails silently when a site changes its markup. Teams usually outgrow it in one of three directions: a script with Google Apps Script and UrlFetchApp (which has the same no-JavaScript limitation), a code-based scraper, or a real browser.

    A browser-based scraper differs in kind, not degree. It loads the page in Chromium, runs its JavaScript, and then extracts from the rendered DOM, which is why a selector that works in DevTools also works there. See how to scrape dynamic websites for the difference in practice.

    In Autonoly, extraction runs in a real Chromium browser (Playwright-based), so JavaScript-rendered content is present. The data extraction step accepts the same XPath or CSS selector you would use in IMPORTXML, list steps can follow a Next button, and results are written to a sheet through the native Google Sheets integration on a schedule you set. It does not use proxies or rotate IPs, so a site that blocks automated traffic outright may still block it; when a CAPTCHA it cannot solve appears, you can take over the browser. The walkthrough in scraping a website to Google Sheets compares the two approaches end to end.

    Why It Matters

    IMPORTXML is the most common way people first pull web data into a spreadsheet, and its failure modes (no JavaScript, no logins, Google's servers doing the fetching, hourly refresh) explain why so many sheet-based scrapers break. Knowing those limits tells you when a formula is enough and when you need a real browser.

    How Autonoly Solves It

    Autonoly loads pages in a real Chromium browser, so content rendered by JavaScript is there to extract. You can reuse the XPath or CSS selector from your IMPORTXML formula in a data extraction step, follow pagination, and write rows to Google Sheets through the native integration on a schedule. It does not provide proxies or IP rotation, and sites that block automation can still block it.

    Learn more

    Examples

    • Using =IMPORTXML(A2, "//title") down a column of URLs to collect the page title of every page in an SEO audit

    • Pulling the price from a server-rendered product page with =IMPORTXML(url, "//span[@itemprop='price']/@content")

    • Replacing an IMPORTXML formula that returns 'Imported content is empty' on a JavaScript-rendered listing page with a scheduled browser workflow that extracts the same fields into Google Sheets

    Frequently Asked Questions

    The fetch succeeded but your XPath matched nothing in the raw HTML. Usually the content is added by JavaScript after load, so it is not in what Google's servers downloaded. Check the page with view-source: or curl. If the data is missing there, no XPath will find it and you need a tool that renders the page in a browser.

    Google's servers could not get a usable response. Common causes are the site blocking Google's fetcher or data-center IPs, a login wall, a malformed or unquoted URL, a missing https:// prefix, or a server error. Test the URL in a private window and check whether the site blocks automated requests.

    Google's help center says import functions check the source for updates hourly while the spreadsheet is open. Reloading the sheet does not force a fetch. Deleting and re-entering the formula does. For a fixed schedule, people use an Apps Script time-driven trigger or move to a scheduled scraper.

    No. The request is made by Google's servers without your cookies or session, so it only sees what an anonymous visitor would see. Pages behind a login need a browser that is signed in, or the site's own API.

    No. It parses the HTML the server returns and never runs scripts. Single-page apps, infinite-scroll lists and prices loaded by an API call after page load are invisible to it. Sometimes the data is embedded as JSON in a script tag, which IMPORTXML can occasionally reach; otherwise use a browser-based scraper.

    IMPORTHTML imports a whole HTML table or list by its position on the page and needs no XPath. IMPORTXML runs any XPath query, so it can pick individual elements or attributes. Both fetch the raw HTML from Google's servers and share the same limitations.

    Related terms, automations and guides

    Where this concept shows up in practice.

    DefinitionIMPORTHTMLIMPORTHTML is a Google Sheets function that imports a whole HTML table or list from a web page into your spreadsheet, chosen by its position on the page. It is the quickest way to pull a static table into Sheets, and it shares IMPORTXML's limits: no JavaScript, no logins, hourly refresh.DefinitionGoogle Apps ScriptGoogle Apps Script is Google's cloud-hosted JavaScript platform for automating Google Workspace: Sheets, Gmail, Drive, Docs, Calendar and Forms. Scripts run on Google's servers, can be triggered on a schedule or by events, and are limited by daily quotas such as a 6-minute cap per execution.DefinitionGoogle Sheets APIThe Google Sheets API is Google's REST API for reading and writing Google Sheets from your own code. Version 4 exposes cell values, formatting, charts and sheet structure, and is limited by per-minute quotas of 300 requests per project and 60 per user, separately for reads and writes.DefinitionCSS SelectorA CSS selector is a pattern used to identify and target specific HTML elements on a web page, widely used in browser automation to locate buttons, forms, text, and other interactive elements.DefinitionData ScrapingData scraping is the broad practice of programmatically extracting data from any digital source — websites, applications, databases, documents, or APIs. It encompasses web scraping, screen scraping, and other automated extraction techniques.DefinitionStructured DataStructured data is information organized in a predefined, predictable format — typically rows and columns in databases, spreadsheets, or tabular files like CSV and JSON. Each field has a defined type and position, making it easy to query, filter, and analyze programmatically.GuideHow to Scrape and Crawl Dynamic Websites (Why JavaScript Pages Come Back Empty)Why requests, BeautifulSoup and Google Sheets' IMPORTXML return empty results on JavaScript pages, and the four ways to get the data: embedded JSON, the site's own XHR/JSON endpoints, a rendered browser with proper waits, and handling infinite scroll, load-more buttons and JS-built links when crawling.GuideIMPORTXML "Could Not Fetch URL" and "Imported Content Is Empty": Causes and FixesWhy Google Sheets' IMPORTXML and IMPORTHTML return "Could not fetch url", "Imported content is empty" or endless Loading, how to tell which cause you have in a minute, and what to use when the page is JavaScript-rendered, blocked or behind a login.

    Stop reading about automation.

    Start automating.

    Describe what you need in plain English. Autonoly's AI agent builds and runs the automation for you — no code required.

    See Features