Google Sheets function · Web and import
IMPORTHTML in Google Sheets: syntax and examples
IMPORTHTML loads one table or one list from a public web page and keeps it refreshed. You pick the element by type and by its number on the page. It is the quickest way to get a table with no XPath knowledge.
Syntax
IMPORTHTML(url, query, index)
Arguments
| Argument | Type | Required | What it does |
|---|---|---|---|
url | string | yes | The page address, with http:// or https://. |
query | string | yes | Either "table" or "list": the kind of element to import. |
index | number | yes | Which table or list on the page, counted from 1 in page order. |
Examples
The examples use this table, starting in A1:
| https://en.wikipedia.org/wiki/Comma-separated_values |
=IMPORTHTML(A1, "table", 1)Result:
| Comma-separated values | |
| Filename extension | .csv |
| Internet media type | text/csv[1] |
| Uniform Type Identifier (UTI) | public.comma-separated-values-text[2] |
| UTI conformation | public.delimited-values-text[2] |
| Type of format | multi-platform, serial data streams |
| Container for | database information organized as field separated lists |
| Standard | RFC 4180 |
The first table on this page is the info box at the top, so the import starts with the page name and has an empty row.
Run in a Google Sheet (English US locale) on . The result changes over time; this is the value on the run date.
=IMPORTHTML(A1, "table", 2)Result:
| Year | Make | Model | Description | Price |
| 1997 | Ford | E350 | ac, abs, moon | 3000 |
| 1999 | Chevy | Venture "Extended Edition" | 4900 | |
| 1999 | Chevy | Venture "Extended Edition, Very Large" | 5000 | |
| 1996 | Jeep | Grand Cherokee | MUST SELL! air, moon roof, loaded | 4799 |
The second table. The index counts every table in page order.
Run in a Google Sheet (English US locale) on . The result changes over time; this is the value on the run date.
=IMPORTHTML(A1, "list", 1)Result:
| Main page |
| Contents |
| Current events |
| Random article |
| About Wikipedia |
| Contact us |
The first bulleted or numbered list, one item per row.
Run in a Google Sheet (English US locale) on . The result changes over time; this is the value on the run date.
=INDEX(IMPORTHTML(A1, "table", 2), 2, 3)Result: E350
A single cell from the imported table: row 2, column 3 of the second table.
Run in a Google Sheet (English US locale) on . The result changes over time; this is the value on the run date.
=ROWS(IMPORTHTML(A1, "table", 1))Result: 9
How many rows the first table has now, a quick way to watch for changes.
Run in a Google Sheet (English US locale) on . The result changes over time; this is the value on the run date.
Common errors
- The index counts every table or list in page order, including small layout tables. Try 1, 2, 3 until you find the right one.
- An index larger than the number of elements returns #N/A.
- The query must be "table" or "list". Anything else, such as "chart", returns #VALUE!.
- Tables built by JavaScript are not in the downloaded HTML. If the page shows a table but the import is empty, use IMPORTXML or the site's data export.
Compared with Excel
Excel has no IMPORTHTML. Data > From Web in Power Query reads tables from a page in a similar way.