How to extract a HTML table from a url
To extract an HTML table from a URL in Google Sheets, you can use the IMPORTHTML
function. This function allows you to import data from an HTML table or list on a webpage.
Here's a step-by-step guide on how to use the IMPORTHTML
function:
- Open a new Google Sheets document.
- In an empty cell, type the following formula:
Replace "URL" with the URL of the webpage containing the table you want to import. Replace "index" with the index number of the table on the webpage (1 for the first table, 2 for the second, and so on).=IMPORTHTML("URL", "table", index)
- Press Enter, and the table should now appear in your Google Sheets document.
Example
Let's extract the table of the "List of countries by population" from the following Wikipedia page: https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population
- Open Google Sheets and click on an empty cell.
- Type the following formula:
=IMPORTHTML("https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population", "table", 1)
- Press Enter, and the table should now appear in your Google Sheets document.
In this example, we used the first table (index 1) from the Wikipedia page. If you want to extract a different table, change the index number accordingly.
Did you find this useful?