The IMPORTHTML function in Google Sheets is a powerful tool for users who need to extract structured data directly from web pages. It allows you to pull in either tables or lists from a specified HTML URL, enabling seamless integration of online data into your spreadsheets for analysis or reporting.
Syntax
IMPORTHTML(url, query, index)
- url: The web address of the HTML page from which you want to import data.
- query: Specifies the type of data to import, which can either be “table” or “list”.
- index: The number of the specific table or list on the page that you wish to import, with the first one being 1.
Example #1
=IMPORTHTML("https://www.example.com", "table", 1)
This function fetches the first table from the specified URL, displaying data like names and addresses. Result: Name: John, Address: 123 Main St.
Example #2
=IMPORTHTML("https://www.example.com", "list", 1)
This retrieves the first list from the webpage, which could be items in a bullet list. Result: Item 1: Apples, Item 2: Bananas.
Example #3
=IMPORTHTML("https://www.example.com", "table", 2)
This command takes data from the second table on the given page, providing insights such as numerical values or statistics. Result: Stat: 25%, Count: 150.
Error handling
- REF!: This occurs when the specified index does not correspond to any existing table or list on the page.
- VALUE!: Indicates that the parameters used in the function are incorrect or not formatted properly.
- N/A!: Happens when there’s no data to retrieve, potentially due to changes on the source webpage or a broken link.