Tiny Lever home

How to export an HTML table to CSV

A CSV file is plain text where each line is a row and commas separate the columns. Almost every spreadsheet, database and data tool can read one, which makes it the easiest way to move a table off a web page. Here are three ways to get there, from no-tools to a little scripting.

Method 1: go through a spreadsheet

  1. Select the table on the page and copy it (Ctrl+C).
  2. Paste into Google Sheets or Excel.
  3. Tidy anything that came across badly (see the notes below).
  4. In Google Sheets choose File, Download, Comma Separated Values (.csv). In Excel choose File, Save As, and pick CSV UTF-8 (Comma delimited) as the type.

Only the sheet you are on is saved to a CSV file. If your data is on several sheets, each needs its own export.

Method 2: a few lines in the browser console

If you are comfortable with developer tools, you can build the CSV directly from the page. Open the console (F12, then the Console tab) and run this, changing the 0 to pick which table on the page you want (0 is the first):

const t = document.querySelectorAll("table")[0];
const q = s => '"' + s.replace(/"/g, '""') + '"';
const csv = [...t.rows].map(r =>
  [...r.cells].map(c => q(c.innerText.trim())).join(",")
).join("\n");
const a = document.createElement("a");
a.href = URL.createObjectURL(new Blob(["" + csv], {type: "text/csv"}));
a.download = "table.csv";
a.click();

It wraps each value in quotes and doubles any quotes inside, which is what the CSV format requires. The  at the start is a byte-order mark; it helps Excel recognise accented characters (see below). Be careful about pasting code into your console that you do not understand. Some sites also block it, and a few browsers warn you before you can paste.

The limits of this snippet: it does not expand merged cells, so rows can end up with different numbers of columns, and it will not see tables inside other frames on the page.

Method 3: a browser extension

Extensions can find the tables for you and save a file in one click. When choosing one, check what permissions it asks for and whether the data stays on your computer. We cover our own at the end of this guide.

Things that commonly go wrong

Accented characters turn into gibberish

Text such as "São Paulo" showing as "São Paulo" means the file is UTF-8 but Excel guessed another encoding. Save as "CSV UTF-8", or add a byte-order mark as in the script above. Alternatively, in Excel use Data, From Text/CSV and set the file origin to UTF-8 when importing.

Commas inside values split a column

A value like "Smith, John" must be wrapped in quotes in the file. Spreadsheet exports and the script above do this. Hand-built CSVs often do not.

Semicolons instead of commas

In some regions Excel expects semicolons because the comma is the decimal mark. If a file opens as a single column, use Data, From Text/CSV and choose the delimiter yourself.

Leading zeros and long numbers disappear

Zip codes like 02134 or long IDs get turned into numbers when Excel opens a CSV. Import with Data, From Text/CSV and set that column to Text rather than double-clicking the file. Note that this alters how Excel displays the data, not what is in the file; the CSV itself still holds 02134.

Dates change meaning

The text 03/04/2025 is March 4th in some regions and April 3rd in others, and Excel will interpret it using your computer's settings. Where you can, prefer the unambiguous form 2025-04-03.

Check your CSV

Open the file in a plain text editor such as Notepad. If every line has the same number of commas outside quotes, and the header row looks right, any program should read it.

Where TableTidy fits

TableTidy is our Chrome extension for this job. It finds the tables on a page, shows a preview, and (Pro) downloads CSV and Excel files with optional cleanup of merged cells, footnote markers, numbers and dates. Free copies up to 250 rows to the clipboard and includes 5 Pro exports per month. It works in the browser, nothing is uploaded, and there is no account. It has not launched yet; email us and we will tell you once when it does.