How to convert HTML to CSV
Updated · 3 min read
Useful data is often published as a table on a web page — prices, statistics, schedules, reports. Paste the table's HTML (or an entire saved web page) and the converter extracts the first table, uses its header row for column names and gives you a clean CSV ready for a spreadsheet or script.
- In your browser, right-click the table and choose Inspect.
- In the developer tools, right-click the
<table>element and choose Copy → Copy element (or Copy outerHTML). - Paste it into the input box — HTML is detected automatically.
- Download the CSV, or switch the target to Excel or JSON.
Example
HTML input
<table>
<thead>
<tr><th>Rank</th><th>City</th><th>Country</th><th>Population</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>Casablanca</td><td>Morocco</td><td>3,752,000</td></tr>
<tr><td>2</td><td>Fès</td><td>Morocco</td><td>1,256,000</td></tr>
</tbody>
</table>CSV output
Rank,City,Country,Population
1,Casablanca,Morocco,"3,752,000"
2,Fès,Morocco,"1,256,000"The <th> cells become the header, whitespace is cleaned up, and values like 3,752,000 are quoted because they contain the delimiter. Thousands separators are kept as text, exactly as displayed on the page.
Your data stays on your device. The conversion runs in JavaScript inside this tab — files and pasted text are never uploaded to DataSwitch Pro.
How the table is read
- The first
<table>in the pasted HTML is used; if there are more, a notice tells you how many were found. - The first row — usually the
<th>header cells — supplies the column names. - Cell text is extracted without tags; links, bold text and icons are reduced to their visible text.
- Whitespace and line breaks inside cells are collapsed to single spaces.
- Rows from nested tables are not mixed into the outer table.
Merged cells
Cells that use colspan or rowspan span several columns or rows on screen, but their text appears only once in the HTML. The converter keeps the text in the first position and warns you, because the following cells may shift. Check those rows in the output.
A quicker alternative for simple tables
For small tables, you can often select the table on the page, copy it, and paste the text directly — browsers copy table cells separated by tabs. Choose CSV as the source and the tab delimiter is detected. Using the HTML is more reliable for large tables or tables with complex formatting.
Why not enter a URL?
Fetching a page from another website would require sending the address through a server, and most sites block such requests. Keeping the tool paste-based means it works with pages behind logins and intranets, and nothing you convert ever leaves your browser.
Convert HTML to CSV in code
For one-off files the tool above is quickest. To automate the same task in a script or pipeline, these snippets are a good starting point.
Python (pandas)
import pandas as pd # pip install pandas lxml
tables = pd.read_html("page.html") # also accepts a URL
tables[0].to_csv("table.csv", index=False, encoding="utf-8-sig")
Frequently asked questions
Can I convert all the tables on a page?
The first table is converted. To convert another one, copy just that table's HTML, or delete the tables before it in the input.
Why are numbers with commas kept as text?
Values such as 3,752,000 include formatting from the page. They are kept exactly as shown; remove the separators in your spreadsheet if you need numbers.
Can I get Excel or JSON instead of CSV?
Yes. Change the target format to Excel, JSON, SQL or any other supported format.
Does it work with tables built from div elements?
No. Only real <table> markup can be converted; layouts made of div elements have no row and column structure to read.
Is the HTML uploaded?
No. It is parsed locally by your browser.