IMPORTXML function in Google Sheets
Imports data from any of various structured data types including XML, HTML, CSV, TSV, and RSS and ATOM XML feeds.
=IMPORTXML(url, xpath_query, locale)IMPORTXML syntax and parameters
Three arguments, two required.
- urlstringRequired
The URL of the page to examine, including protocol (e.g. http://). The value for url must either be enclosed in quotation marks or be a reference to a cell containing the appropriate text.
- xpath_querystringRequired
The XPath query to run on the structured data. For more information on XPath, see http://www.w3schools.com/xml/xpath_intro.asp.
- localestringOptional
A language and region locale code to use when parsing the data. If unspecified, the document locale is used.
IMPORTXML examples
Formulas you'll actually reuse.
The page's main heading by XPath:
=IMPORTXML("https://example.com/products/42", "//h1")Every link on the page, one per row — an attribute selected with @:
=IMPORTXML("https://example.com/products/42", "//a/@href")
IMPORTXML in Excel
No direct equivalent — here's the way around.
Try IMPORTXML in the playground
Edit the example — nothing to install.
Preloaded with the IMPORTXML formula from Example 1 — change anything and watch it respond.
IMPORTXML errors
What they mean — and the fixes.
#N/AThe XPath matched nothing — pages rendered by JavaScript often have no such node in the raw HTML; test the XPath against view-source.
Related functions
More ways Google Sheets gets this done.
- ENCODEURLEncodes a string of text for the purpose of using in a URL query. .WebExcel
- HYPERLINKCreates a hyperlink inside a cell.WebExcel
- IMPORTDATAImports data at a given url in .csv (comma-separated value) or .tsv (tab-separated value) format.WebNo Excel equivalent
- IMPORTFEEDImports a RSS or ATOM feed.WebNo Excel equivalent
- IMPORTHTMLImports data from a table or list within an HTML page.WebNo Excel equivalent
- IMPORTRANGEImports a range of cells from a specified spreadsheet.WebNo Excel equivalent