Home › Blog › Scrape data into Google Sheets

How to scrape data from a website into Google Sheets

By the ScrapeSheet team · Published August 4, 2026 · Updated November 12, 2026 · 6 min read

Laptop with a blank screen on a light wooden desk beside a small cactus and a photo frame

In short: Scrape data from a website to Google Sheets with IMPORTHTML when the data sits in an HTML table or list: give it the URL, "table", and the table's position on the page. Use IMPORTXML for single values. If the page builds its data with JavaScript, the formulas see nothing, so extract the rendered page and import the result.

How do you import a table from a URL into Google Sheets?

Use IMPORTHTML. It reads a page's HTML and returns one table or list, picked by its position on the page. The syntax is IMPORTHTML(url, query, index), where query is "table" or "list" and index starts at 1. Tables and lists are counted separately, so a page can have both a table 1 and a list 1.

Worked example: a public Wikipedia table

Wikipedia's "List of U.S. states and territories by population" page is a good test: it is public, and its tables are in the page's HTML.

  1. Create a new sheet. In A1, paste the page address: https://en.wikipedia.org/wiki/List_of_U.S._states_and_territories_by_population
  2. In B1, type 1. This is the table index.
  3. In A3, enter the formula below. Keeping the URL and the index in cells makes them easy to change.
=IMPORTHTML(A1, "table", B1)
  1. Wait a few seconds. While it shows Loading..., Google is fetching the page.
  2. Check the result. At the time of writing (November 2026), table 1 is the main population table: a rank column, the state or territory, then the population estimates and census counts. Table 3 lists the states grouped by census division and region, with a subtotal for each.
  3. To keep only some columns, wrap the formula. This one keeps the state name and the latest population estimate:
=CHOOSECOLS(IMPORTHTML(A1, "table", B1), 2, 3)

Header cells may carry footnote markers such as [8]. Rename those headers by hand if you need clean labels. If your spreadsheet uses a comma as the decimal separator, separate the arguments with semicolons instead of commas.

How to find the table index

Wikipedia changes, like every other site, so do not trust a fixed number. Three ways to find the right one:

  1. Trial and error. Change B1 to 2, 3, 4... until your table appears. With the URL in a cell, this takes seconds.
  2. View the source. Press Ctrl+U (Cmd+Option+U on a Mac) to open the page source, then Ctrl+F (Cmd+F on a Mac) and search for <table. Chrome shows a counter such as 1/6; step through until you reach your table. Its number is your index.
  3. Ask the browser console. Right-click any cell of the table and choose Inspect. Open the Console tab and type the line below. It returns the table's position on the page.
[...document.querySelectorAll("table")].indexOf($0.closest("table")) + 1

The console counts tables in the page as your browser shows it, including any that scripts added. The formula only counts tables in the HTML source, so treat the console number as a starting point and try the numbers next to it if the result is wrong. Note that layout boxes, such as navigation boxes at the bottom of a page, are often tables too.

How do you pull a single value with IMPORTXML?

When you need one field, such as a price, a title, or a rating, rather than a whole table, IMPORTXML targets elements with an XPath query (XPath is the W3C language for selecting parts of a document):

=IMPORTXML("https://example.com/product", "//span[@class='price']")

To find the XPath, right-click the element in your browser, choose Inspect, then right-click the highlighted node and choose Copy > Copy XPath. Paste it as the second argument, changing any double quotes inside the XPath to single quotes so the formula stays valid. IMPORTXML is powerful but brittle: when the site changes its markup, the formula breaks and you have to fix the XPath. For a full example that logs prices over time, see the price scraper in Google Sheets guide.

Person in a suit holding a tablet with a rising blue bar chart extending beside it

What if the page needs JavaScript?

Sooner or later, IMPORTHTML or IMPORTXML will return an error such as #N/A or an empty cell. The usual reasons:

To check whether the data depends on JavaScript, open the page source (Ctrl+U) and search for a value you can see on the page, such as a price or a name. If it is not in the source, no formula will find it. You have two good options:

  1. Look for a file first. Many publishers offer a CSV download or an open data portal. U.S. government datasets, for example, are listed on Data.gov. If a CSV file has a direct link, IMPORTDATA("file URL") loads it into the sheet.
  2. Extract the rendered page. Use a browser tool that reads the page as you see it, then paste or import the rows. The next section shows how.

Only import public pages. Check the site's terms of use and robots.txt, and never work around logins, CAPTCHAs, paywalls, or rate limits. Wikipedia text is licensed under CC BY-SA, so credit it if you republish the data. This is general information, not legal advice; read "Is web scraping legal?" for more.

How to do it with ScrapeSheet

When formulas cannot reach the data, extract it with ScrapeSheet. It runs on the page you have open, as your browser displays it, so it can also see content that scripts add after loading. It exports to CSV or the clipboard, and Google Sheets takes both cleanly.

  1. Install ScrapeSheet from the Chrome Web Store and open the page you want.
  2. Click the icon, then Extract. It detects the tables and lists on the page. If the page is messy, describe the columns in plain language (Pro, with your own Claude or OpenAI key).
  3. Copy the result to the clipboard and paste it into a sheet, or export it as a CSV file.
  4. For a CSV, in Google Sheets use File > Import > Upload and choose to insert a new sheet or replace the current data.

The free plan exports up to 20 rows and reads one page per run. ScrapeSheet Pro (€12.99 per month) removes both limits and follows pagination; see scraping multiple pages. Unlike a formula, an extraction does not refresh by itself: run it again when you want new data.

Which method should you use?

MethodBest forUpdates
IMPORTHTMLTables and lists in the HTMLAbout hourly
IMPORTXMLSingle values by XPathAbout hourly
IMPORTDATAPublished CSV filesAbout hourly
Extract and importJavaScript or multipage dataWhen you rerun it

You do not need an extension for the Wikipedia example above: IMPORTHTML pulls all of it for free and keeps it current. Reach for an extraction tool when the source shows nothing, or when the data spans many pages. If your data lives in Excel rather than Google Sheets, the same ideas apply; see how to scrape a website to Excel. More guides are on the ScrapeSheet blog.

FAQ

How do I import a table from a website into Google Sheets?
Put the page URL in cell A1 and use =IMPORTHTML(A1, "table", 1). Change the last number until you get the right table; the index counts the tables in the page's HTML source, starting at 1.

How often does IMPORTHTML refresh?
Google's documentation says IMPORTHTML, IMPORTXML, IMPORTDATA, and IMPORTFEED recalculate about every hour (IMPORTRANGE about every 30 minutes). You cannot set a faster interval in the formula. To keep a fixed copy, copy the range and use Paste special > Values only.

Why does IMPORTHTML return an error or nothing?
Common causes are a wrong table index, a page that builds its data with JavaScript, a site that blocks Google's fetcher, or content behind a login. Check the page source for the data first; if it is not there, extract the rendered page and import a CSV.

How do I scrape a JavaScript page into Google Sheets?
First, look for a CSV download or an open data file, which IMPORTDATA can load. Otherwise, use a browser extension like ScrapeSheet to extract the rendered page, then paste the rows or use File > Import in Google Sheets.

Sources

General information, not legal advice. Always check the website's terms and the data-protection rules that apply to you.

Keep reading

← Back to the blog · ScrapeSheet home