OĞUZ EROLAI·ADS·APPS

Google Sheets: Import Data from a Website with IMPORTHTML, IMPORTXML and a Price History

14 min readPublished: Updated:
CONTENTS9 sections

Google Sheets has four built-in formulas for pulling prices from a supplier or competitor website: IMPORTHTML for an HTML table or list, IMPORTXML with an XPath query when there is no table, IMPORTDATA for a CSV file at a fixed address, and IMPORTFEED for an RSS or Atom feed. According to Google, IMPORTHTML, IMPORTXML and IMPORTDATA check for updates every hour while the document is open. Each refresh replaces the result and the cell keeps no earlier value. If the price is loaded later by JavaScript or sits behind a login, the cell may stay empty or return an error. For a history you need a small Apps Script that copies the values to a separate sheet every morning.

I read the linked Google Help and developer pages on 2026-10-31. I have not run the formulas or the script in a real Google file; the syntax comes from Google’s documentation, the example figures from a Python script.

Four formulas: which one fits which source?

The format in which the source publishes the price decides which import formula fits.

FormulaWhenLimit
IMPORTHTML(A1,"table",1)The price sits in a table or a bulleted listIf the table order shifts, it returns another table without an error
IMPORTXML(A1,"//…")Prices sit on product cards, no tableXPath depends on class names; empty or an error after a redesign
IMPORTDATA(A1)The supplier publishes a CSV or TSV at a fixed addressGoogle’s page lists no delimiter argument
IMPORTFEED(A1,"items title")The supplier announces price-list updates in a feedNo prices; can serve as an alert that the list changed

Google’s examples separate arguments with commas; its Turkish Help pages use semicolons. Use the separator your spreadsheet locale expects.

IMPORTHTML: tables and lists

The syntax is IMPORTHTML(url, query, index). According to Google’s IMPORTHTML page, the query is "table" or "list", the index starts at 1, and tables and lists are counted separately.

A1: https://supplier-a.example/price-list
B1: =IMPORTHTML(A1,"table",1)

If the first table is not the expected one, count the tables with right-click > Inspect instead of guessing the index. Then compare headers and a few rows with the page; a formula that returns data has not proved that the columns mean what you need.

IMPORTXML: XPath when there is no table

The syntax is IMPORTXML(url, xpath_query, locale). Google says it reads XML, HTML, CSV, TSV and RSS/Atom feeds; without a locale it uses the document’s. For prices on product cards you set up two formulas side by side:

B2: =IMPORTXML(A1,"//div[contains(@class,'product-card')]//span[contains(@class,'code')]")
C2: =IMPORTXML(A1,"//div[contains(@class,'product-card')]//span[contains(@class,'price')]")

I used contains(@class,'price') rather than @class='price' because an element carrying several classes fails the exact match. The real trap is alignment. If one card shows “Price on request”, the price column comes back one row short and every later price shifts onto the code above it, since the formulas return only matching elements. If the two columns have different row counts, do not use the result; the script below catches the row with a missing price.

IMPORTDATA: the supplier’s CSV file

=IMPORTDATA(A1) fetches .csv or .tsv data from the address in A1 (Google). Google’s page shows no delimiter or locale argument; a semicolon-separated file may land in one column (untested), so ask for a comma-separated file or a TSV.

How often does it refresh, and what happens when the file is closed?

According to Google’s page on import functions, IMPORTDATA, IMPORTHTML and IMPORTXML check for updates every hour while the document is open; I found nothing on Google’s pages about what happens while it is closed. The calculation settings page gives 30 minutes for IMPORTRANGE and 1 hour for IMPORTHTML, IMPORTFEED, IMPORTDATA and IMPORTXML, without separating open from closed.

Overwriting the cells with the same formula, or deleting and re-adding them, triggers a refresh. Opening the document and reloading the browser does not. So the price you see in the morning does not tell you when it was fetched.

Usage limit. Google gives no number. The limit belongs to the document’s creator and counts across all open documents that person created. When exceeded, the cell shows “Loading data may take a while because of the large number of requests.” Google advises fewer import functions, so I recommend one formula per source page, not one per item.

Allow access. When the first import formula is added, a banner appears and every import in the file stays blocked until an editor clicks Allow access; Google says this can only be undone through version history.

Empty cells, #N/A and the wrong table arriving silently

An import formula fails in three ways: it returns an error, it returns nothing, or it returns the wrong data with no warning. The third is the costliest, because nobody notices.

Prices loaded by JavaScript. If the price appears a few seconds after the page loads, the page is dynamic. Google’s import pages say nothing about JavaScript; I assume the formula reads the HTML the server sends first and never sees the price added later. The result may be an empty cell or #N/A, Google’s “value not available” error (NA function). Quick check: right-click, View page source; if the price is not there, the formula most likely cannot see it either. Ask the supplier for a CSV. If the supplier offers an API, fetching JSON with Apps Script is a separate job.

Pages behind a login. The formula does not sign in (my inference); do not try to get around the login, ask for a file.

Errors Google names. The import page lists “Result too large” (narrow the XPath), “Admin has not allowed imports from…” (your Workspace admin must allow that address) and the usage-limit message above.

Silent breakage. When the supplier adds a promotions table at the top, "table",1 returns it without an error. If the column order changes, stock arrives where price should be. The header and row-count checks show the first the same morning. They miss the second: stock is a positive number too, so it passes and is written as price. Check the price header now and then.

Example: three suppliers, 90 items, 23 price changes in 30 days

The company, suppliers and figures are fictional; I calculated and checked every number in a Python script.

The purchasing team of a pump and valve manufacturer tracks 90 items from three suppliers. A sells 40 stainless fittings, priced in an HTML table over two pages. B sells 30 seals, with prices loaded by JavaScript. C sells 20 bearings shown as cards on three category pages; on the third, prices appear only after a dealer login.

The first setup used 7 formulas:

FormulaItemsResult
A-1, A-2 · IMPORTHTML25 + 15Arrived
B-1, B-2 · IMPORTHTML16 + 14Empty: JavaScript
C-1, C-2 · IMPORTXML8 + 6Arrived
C-3 · IMPORTXML6Empty: dealer login

Three of the 7 came back empty: 54 items reached the sheet, 36 did not. B agreed to publish a daily CSV, so one IMPORTDATA replaced two IMPORTHTML formulas. C offered no file, so C-3’s 6 items left the formulas and are entered by hand weekly. The final setup has 5 formulas (2 IMPORTHTML, 1 IMPORTDATA, 2 IMPORTXML) covering 84 items.

A daily snapshot then ran for 30 days. There were 23 price changes (11 at A, 8 at B, 4 at C). 21 entered the history, 2 of them a day late, because a daily snapshot records the day it sees a change, not the day it happened.

  • 2 missed: B007 went on a 10 percent promotion at 10:00 on day 12 and returned to its old price at 16:00. A daily snapshot sees neither.
  • Day 16: A added a 5-row promotions table at the top and "table",1 returned it. The header did not match, so A-1’s 25 items were skipped; without the check, 5 wrong rows would have entered the history. A-1’s index was adjusted for the new table and the header check stayed in place; A010’s increase from the day before appeared on day 17.
  • Days 9 and 22: B’s CSV arrived with 14 rows instead of 30, and C-1 returned an error value. The script skipped both sources those days and logged why.

After 30 days the history held 2,457 rows: 84 items × 30 days minus 63 skipped. One example: A017 rose from 220.00 to 228.80 on day 4 and fell to 224.40 on day 26. With the formula alone, day 30 would show 19 items priced differently, but not that A003 and A017 changed twice.

Keeping prices with dates: a daily snapshot in Apps Script

An import formula keeps no history; for that I recommend an Apps Script that checks the formula’s current result every morning and appends it, with the date, as values on a separate sheet. Layout: each source has its own tab with the address in H1, so write $H$1 instead of A1 in the formulas. IMPORTHTML and IMPORTDATA sit in A1 and bring their own header; for IMPORTXML the formulas sit in A2 (code) and C2 (price) and you type the header into A1. Column A holds the supplier code and column C the price; if your source differs, set CODE and PRICE to those columns’ positions counted from 0.

Setup in three steps:

  1. In the price file, open Extensions > Apps Script, paste the code and save. The script must be bound to the file; only then does getActive find it. Replace the SOURCES list with your own tab names, expected row counts and headers; add empty History and Log tabs.
  2. Run takeSnapshot once by hand in the editor, approve Google’s permission prompt and check for one OK row per source in Log.
  3. Run installTrigger once. Every run adds another trigger, so delete extras on the Triggers page. In the first week, compare a few prices daily with the supplier page by hand (see the box below).
const SOURCES = [ // tab name, expected rows, header in A1
  {tab: 'A-1', rows: 25, header: 'Code'}, {tab: 'A-2', rows: 15, header: 'Code'},
  {tab: 'B', rows: 30, header: 'Code'},
  {tab: 'C-1', rows: 8, header: 'Code'}, {tab: 'C-2', rows: 6, header: 'Code'},
];
const CODE = 0, PRICE = 2; // column position, counted from 0

function takeSnapshot() {
  const ss = SpreadsheetApp.getActive();
  const history = ss.getSheetByName('History'), log = ss.getSheetByName('Log');
  const now = new Date();
  SOURCES.forEach(s => {
    const sh = ss.getSheetByName(s.tab);
    sh.getRange('A1:F2').getFormulas().forEach((row, i) => row.forEach((f, j) => {
      if (f) sh.getRange(i + 1, j + 1).setFormula(f); // rewrite the same formula
    }));
    SpreadsheetApp.flush();
    Utilities.sleep(20000);
    const data = sh.getDataRange().getValues();
    const rows = data.slice(1).filter(r => r[CODE] !== '');
    let problem = '';
    if (String(data[0][CODE]) !== s.header) problem = 'header differs: ' + data[0][CODE];
    else if (rows.length !== s.rows) problem = rows.length + ' rows, expected ' + s.rows;
    else if (rows.some(r => typeof r[PRICE] !== 'number' || r[PRICE] <= 0)) problem = 'non-numeric price';
    if (problem) { log.appendRow([now, s.tab, 'NOT WRITTEN', problem]); return; }
    const out = rows.map(r => [now, s.tab, r[CODE], r[PRICE]]);
    history.getRange(history.getLastRow() + 1, 1, out.length, 4).setValues(out);
    log.appendRow([now, s.tab, 'OK', out.length]);
  });
}

function installTrigger() {
  ScriptApp.newTrigger('takeSnapshot').timeBased().everyDays(1).atHour(7).create();
}

Why it works this way:

  • Rewriting the same formula. Google says overwriting with the same formula triggers a refresh. flush applies pending changes (SpreadsheetApp); the 20-second wait is my starting suggestion.
  • Three checks, no partial data. Header, expected row count, numeric prices. If any fails, nothing from that source is written and the reason goes to Log. Writing yesterday’s price in place of a missing one makes the history misleading; a gap is honest.
  • Prices as text. A price written as text, such as “1,234.50” plus a currency code, fails the number check. In the first empty column right of the output, say D2, strip everything except digits and the point, fill down and set PRICE to 3: =VALUE(REGEXREPLACE(C2,"[^0-9.]","")). Both REGEXREPLACE and VALUE are Google functions; for a source with a decimal comma use [^0-9,], If your file’s locale does not match the source’s decimal mark, VALUE may return a wrong number that passes the number check. Untested as well.

Trigger and quota. The installable triggers page says a trigger set for an hour may run between that hour and the next, so the script may run at any minute between 07:00 and 08:00. It runs under the creating account; I assume its quota applies and snapshots stop if the account is closed (my inference). According to the Apps Script quotas page (last updated 2026-09-03), total trigger runtime is 90 minutes a day for consumer accounts and 6 hours for Google Workspace, with at most 6 minutes per execution; quotas can change without notice.

Two unverified assumptions that change the outcome

  1. That a script rewrite triggers a refresh, even in a closed file. Google describes it for manual edits and says nothing about closed files. If it fails, the script writes the old value with today’s date and no check catches it; one stale value in step 3’s manual comparison means the wait is too short or the rewrite does not work.
  2. That JavaScript pages come back empty. An inference; try the formula on that page once before asking for a file.

Before reading a website automatically, check its terms of use, its robots.txt file and whether the page contains personal data, and ask the supplier where you can; I cover that framework, with a short email to the supplier, in importing website data into Excel.

Where Sheets is enough and where an application starts

What decides it is whose decision the price data feeds and whether that decision needs a record. For a few sources one person reviews, Sheets plus a snapshot script is enough. If you observe one of the last two rows below, a separate solution is worth weighing.

What you observeWhat is enough
Only today’s price mattersThe import formula
You need the day a price changedImport formula + daily script
Same-day promotions matterAn hourly script, if the source’s terms and quota allow
The “large number of requests” error appears, or history would stop when the script’s owner leaves the accountA scheduled import running on a server
Different people propose and approve prices, or the history will serve as evidence with a supplierA web app with roles, approval and an audit trail

A price behind a login is not solved by a formula or a server; as with C-3, the most reliable route is asking the supplier for a file or an API. A scheduled import combines emailed lists, CSVs and formula sources in one fetch log and can be built so it does not depend on one employee’s account; see the scheduled API data import app.

In an approval app, scheduled fetching, dated history and a proposal-and-approval screen can be built as needed, with the scope set out in writing at the first step. It runs on a server that can be opened in your company’s name, the data is yours to export to Excel or CSV at any time, small and mid-sized teams pay no per-user licences (the cost is the server plus maintenance), and the source code sits in a repository you can access with run instructions, a dependency list and known limitations.

If one supplier has a clean table, or you need a few prices once, I would not recommend commissioning an application; the formula is enough. Competitor retail prices are a separate job built on matching equivalent products; see competitor price tracking.

Frequently Asked Questions

Can one formula pull several tables from the same page?

Not with IMPORTHTML: the index selects a single table or list, so each table needs its own formula. In IMPORTXML one XPath can cover several tables, but rows mix together and the alignment trap grows.

Can I put the last fetch time next to the formula with NOW()?

In a neighbouring cell, yes; what Google forbids is an import formula referencing volatile functions such as NOW, RAND or RANDBETWEEN, directly or indirectly (TODAY is the exception, updating at most once a day). But that clock shows when the sheet recalculated, not when the import refreshed (my inference). Let the script write the fetch time.

How do I freeze an imported table so it stops being a formula?

Copy the range and use Paste special > Values only. The frozen table never refreshes again; it suits a one-off comparison, not ongoing tracking.

What the first meeting covers

You can send the source page addresses and the items you want to track through the contact page; which sources suit a formula and which need a file request is discussed in the first meeting. The first meeting is paid.

Back to top ↑