Going Stellar

Home/Google Sheets reference

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

ArgumentTypeRequiredWhat it does
urlstringyesThe page address, with http:// or https://.
querystringyesEither "table" or "list": the kind of element to import.
indexnumberyesWhich 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 typetext/csv[1]
Uniform Type Identifier (UTI)public.comma-separated-values-text[2]
UTI conformationpublic.delimited-values-text[2]
Type of formatmulti-platform, serial data streams
Container fordatabase information organized as field separated lists
StandardRFC 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:

YearMakeModelDescriptionPrice
1997FordE350ac, abs, moon3000
1999ChevyVenture "Extended Edition"4900
1999ChevyVenture "Extended Edition, Very Large"5000
1996JeepGrand CherokeeMUST SELL! air, moon roof, loaded4799

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.

Sources

  1. IMPORTHTML (Docs Editors Help)

Markdown version · All functions