# IMPORTXML in Google Sheets: syntax and examples

URL: https://goingstellar.ro/reference/sheets/importxml/

IMPORTXML downloads a page or feed and returns the nodes that an XPath query selects. It works on the HTML a server sends, so it is good for titles, links, prices and any text that is already in the source. Results change when the page changes.

## Syntax

```
IMPORTXML(url, xpath_query)
```

## Arguments

- `url` (string, required: yes): The page or feed address, with http:// or https://. A cell reference works.
- `xpath_query` (string, required: yes): An XPath expression that picks the nodes to return, for example "//h1".

## Examples

The examples use this table, starting in A1:

| https://en.wikipedia.org/wiki/Google_Sheets |
|---|


```
=IMPORTXML(A1, "//title")
```

Result: `Google Sheets - Wikipedia`

The page title, read from the URL stored in A1. Run in a Google Sheet (English US locale) on 2026-11-29. The result changes over time; this is the value on the run date.

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

Result: `Google Sheets`

The text of the main heading. Run in a Google Sheet (English US locale) on 2026-11-29. The result changes over time; this is the value on the run date.

```
=IMPORTXML(A1, "//h1/@id")
```

Result: `firstHeading`

An attribute instead of text: the id of the h1 element. Run in a Google Sheet (English US locale) on 2026-11-29. The result changes over time; this is the value on the run date.

```
=INDEX(IMPORTXML(A1, "//h2"), 1)
```

Result: `Contents`

The first of many matches. IMPORTXML returns a column, INDEX picks one cell. Run in a Google Sheet (English US locale) on 2026-11-29. The result changes over time; this is the value on the run date.

```
=COUNTA(IMPORTXML(A1, "//h2"))
```

Result: `8`

How many second-level headings the page has right now. Run in a Google Sheet (English US locale) on 2026-11-29. The result changes over time; this is the value on the run date.

## Common errors

- A query that matches nothing returns #N/A. Check the XPath against the page source, not the rendered page.
- Content that a script adds after loading is not in the downloaded HTML, so IMPORTXML cannot see it.
- The URL needs the protocol. Plain text such as "not a url" returns #N/A, the same error as an empty match.
- Each call is a web request, so many IMPORTXML formulas in one file make it slow to recalculate.

## Compared with Excel

Excel has no IMPORTXML. The nearest tools are WEBSERVICE with FILTERXML on Windows, or Power Query.

## Related functions

- [IMPORTHTML](https://goingstellar.ro/reference/sheets/importhtml/)
- [IMPORTRANGE](https://goingstellar.ro/reference/sheets/importrange/)
- [IMPORTDATA](https://goingstellar.ro/reference/sheets/importdata/)
- [REGEXEXTRACT](https://goingstellar.ro/reference/sheets/regexextract/)
- [QUERY](https://goingstellar.ro/reference/sheets/query/)

## Sources

- [IMPORTXML (Docs Editors Help)](https://support.google.com/docs/answer/3093342)

