0
0
Google-sheetsHow-ToBeginner ยท 3 min read

How to Use IMPORTHTML in Google Sheets: Syntax and Examples

Use the IMPORTHTML function in Google Sheets to import data from a table or list on a web page by specifying the URL, the element type ("table" or "list"), and the index of the element. For example, =IMPORTHTML("https://example.com", "table", 1) imports the first table from the page.
๐Ÿ“

Syntax

The IMPORTHTML function has three parts:

  • url: The web page address in quotes.
  • query: The type of element to import, either "table" or "list".
  • index: The number of the table or list on the page, starting at 1.
plaintext
=IMPORTHTML(url, query, index)
๐Ÿ’ป

Example

This example imports the first table from Wikipedia's List of countries by population page. It shows how to pull live data into your sheet.

plaintext
=IMPORTHTML("https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population", "table", 1)
Output
A table with country names, populations, and other data from the Wikipedia page's first table.
โš ๏ธ

Common Pitfalls

  • Using the wrong query value: only "table" or "list" are valid.
  • Incorrect index: If the index is too high, the function returns an error because that element doesn't exist.
  • URL must be a publicly accessible web page; private or login-required pages won't work.
  • Dynamic content loaded by JavaScript may not be imported because IMPORTHTML reads the static HTML.
plaintext
=IMPORTHTML("https://example.com", "tables", 1)  // Wrong query, should be "table"
=IMPORTHTML("https://example.com", "table", 10)  // Index too high if less than 10 tables exist
๐Ÿ“Š

Quick Reference

ParameterDescriptionExample
urlWeb page address as a string"https://example.com"
queryType of element: "table" or "list""table"
indexWhich table or list to import (1-based)1
โœ…

Key Takeaways

IMPORTHTML imports tables or lists from public web pages into Google Sheets.
Use "table" or "list" as the query and specify the element index starting at 1.
Ensure the URL is accessible and the element index exists to avoid errors.
IMPORTHTML cannot import content loaded dynamically by JavaScript.
Test your formula with a known URL to understand how it pulls data.