Web Scraping with Google Sheets: 3 Ways to Get Website Data into a Sheet

7 min read

Short answer

Google Sheets can pull data from public web pages with two formulas: IMPORTHTML for tables and lists, and IMPORTXML for anything you can describe with XPath. They refresh about once an hour but cannot read pages that need a login or build their content with scripts. For those, scrape the page in your browser and paste the result.

Add to Chrome
Transcript
  1. Here's how to get data from a website into Google Sheets.
  2. Google Sheets has two formulas for this: Import HTML and Import XML. They read simple public pages, but not pages behind a login or built by scripts.
  3. For any other page, open it in Chrome and say what you need in the side panel.
  4. Check the sample rows, then press Get them all.
  5. When it's done, click View full results, and press Copy on the My data page.
  6. Paste into cell A1 of an empty sheet, and every column lands in its own column.
  7. Easy Scraper AI. Any page, into your sheet.
On this page

Google Sheets has web import built in, and for the right kind of page it is the simplest tool there is: one formula, and the table appears and keeps itself up to date.

The catch is the kind of page. This guide covers the two formulas, what stops them, and what to do when the page is a card list, sits behind a login or loads as you scroll.

What you need

  • A Google account and a blank sheet
  • The address of the page with the data
  • For method 3: Google Chrome or Microsoft Edge, and the Easy Scraper AI extension

Steps

  1. Method 1: IMPORTHTML for a table or a list

    Type the formula into an empty cell with the page address, the word "table" or "list", and a number that says which table or list on the page you want, starting at 1. The formulas are listed just below the steps.

    Tables and lists are numbered separately, so a page can have both a table 1 and a list 1. If the wrong one comes back, raise the number until you get the right one.

  2. Method 2: IMPORTXML for anything else

    IMPORTXML takes the page address and an XPath expression that describes which elements to fetch. "//h2" returns every second-level heading; "//a/@href" returns every link address. It is more flexible than IMPORTHTML and correspondingly fiddlier: you need to look at the page's code to write the expression.

  3. Method 3: scrape in the browser and paste

    Open the page in Chrome, click the Easy Scraper AI icon and say what you want, for example "Title, price and stock of the books on the first 3 pages". Check the sample rows on the confirmation card and press Start (or "Get them all" when there are more pages).

    When it is done, click "View full results". The table opens on the My data page: press Copy and paste into cell A1 of an empty sheet, and every column lands in its own column. For bigger tables, press Download CSV instead and use File → Import in Google Sheets.

    The My data page with a scraped table of 60 books and the Download CSV, Download JSON and Copy buttons

The formulas to copy

IMPORTHTML — a table (the sample from Google's documentation)
=IMPORTHTML("http://en.wikipedia.org/wiki/Demographics_of_India","table",4)
IMPORTXML — every link address on a page
=IMPORTXML("https://example.com/","//a/@href")

Google documents both: IMPORTHTML and IMPORTXML.

Where the formulas stop

  • Public pages only. The page is fetched by Google's servers, not by your browser, so anything behind a login is out of reach.
  • No content built by scripts. The formulas read the page as it is delivered. Lists that are filled in afterwards by JavaScript — most modern shops and search pages — come back empty.
  • One address per formula. A list spread over twenty pages needs twenty formulas, or addresses built from a column of page numbers.
  • Real tables and lists only, for IMPORTHTML. Card grids need IMPORTXML and an XPath for each column.
  • Sites can refuse. A site that blocks automated requests returns an error instead of data.

Which method to use

MethodReadsCannot readStays up to date
IMPORTHTMLReal tables and lists on public pagesCard grids, logged-in pages, script-built contentYes, about hourly
IMPORTXMLAnything on a public page you can describe with XPathLogged-in pages, script-built contentYes, about hourly
Browser scraper, then pasteWhat you see in your browser, including after logging in and across many pagesData the page never showsNo — run it again when you need fresh data
Three ways to get website data into Google Sheets

Tidy the data in Sheets

  • Prices as numbers. Strip the currency sign in a new column:
Google Sheets formula
=VALUE(SUBSTITUTE(B2,"£",""))
  • Remove duplicates. Data → Data cleanup → Remove duplicates.
  • Freeze the header. View → Freeze → 1 row.
  • Keep a snapshot. Imported ranges change when the formula refreshes. To keep today's values, copy the range and use Paste special → Values only.

Common errors

  • "Imported content is empty": the table or list is built by scripts, or the index is too high. Try a lower index, then method 3.
  • "Could not fetch url": the site refused the request or the address is wrong. Open it in a private window to check that it is public.
  • #REF! with "array result was not expanded": something is in the cells the import needs. Clear the area below and to the right of the formula.

Prefer Excel? The same three routes exist there; see how to export website data to Excel.

Common questions

Yes, within limits. IMPORTHTML and IMPORTXML fetch data from public pages. They cannot log in, click, scroll or read content that scripts add after the page loads.

Related guides

Get your first table in a minute

Install the extension, open a page with a list and press Start.