Table of Contents
IMPORTXML imports selected information from a public web page or XML document into Google Sheets. Give it a URL and an XPath expression describing the elements you want, such as headings, link destinations, or a meta description. It reads data available in the fetched document; it does not sign in to a website or run its page scripts like a browser.
Syntax and arguments
=IMPORTXML(url, xpath_query, [locale])The brackets indicate an optional argument; do not type them into the formula.
- url: The full address, including https://, either in quotes or in a cell such as A1.
- xpath_query: A quoted XPath expression, or a reference to a cell containing one.
- locale: An optional language and region code for parsing. If omitted, Sheets uses the spreadsheet locale.

Find the data in the page source
- Open the public page you want to examine.
- Choose View page source in your browser and search for the exact text or element you need.
- Identify the containing tag and any useful attributes, such as an id or class.
- Write an XPath expression that selects that element, then test it in a clear area of the sheet.
The original source is important: browser developer tools can show elements added later by JavaScript, which may be absent from the document IMPORTXML fetches. Not all web data is XML, but XPath can also select elements from HTML.

Start with a simple formula
Put a public page’s full URL in A1. In B1, enter:
=IMPORTXML(A1, "//h1")This selects h1 headings from the fetched page. If there is more than one match, Sheets can return multiple cells. Leave the output area empty so the result can expand.

Use these expressions for other common tasks:
| Data wanted | XPath expression |
|---|---|
| Page title | //title |
| Second-level headings | //h2 |
| Link destinations | //a/@href |
| Meta description | //meta[@name='description']/@content |
| Element with a specific id | //*[@id='main'] |
For example, to select a meta description:
=IMPORTXML(A1, "//meta[@name='description']/@content")A page without that element produces no match. Attribute values must match the actual page; main above is an example, not a universal id. Returned href values may be relative paths rather than complete URLs.


Fix common failures
- No matching data: Check the page source and XPath. Try a broad expression such as
//h1before narrowing it. - Could not fetch the URL: Check the address and whether the page is publicly accessible. A site may block automated fetching even when it opens in your browser. Use an offered export or API when available.
- Result cannot expand: Clear cells occupied by other data in the output area.
- Formula parse error: Check quotation marks and argument separators. Some spreadsheet locales use semicolons instead of commas.
- Loading or too many requests: Reduce repeated import formulas and reuse imported results elsewhere in the sheet. Do not treat the function as a real-time monitoring system.
Choose the right import function
For a complete HTML table or list, IMPORTHTML may be simpler. For CSV or TSV files, use IMPORTDATA. See ways to import website data into Google Sheets. To pull cells from another spreadsheet, use IMPORTRANGE instead of trying to scrape its web page.
Google documents the arguments in its IMPORTXML reference. Website markup can change, so check important imported values against the source rather than assuming the same XPath will work indefinitely.
Reader Comments 0
Sign in with email or Google to join the discussion.