How to Export a Scraped Table to CSV with Vibium
Scrape an HTML table and export it to CSV with Vibium in Python — read rows with findAll(), build records, and write them with the built-in csv module.
To export a scraped table to CSV with Vibium, read the rows with findAll(), pull each cell's text(), then write the records to disk with Python's built-in csv module. Vibium is AI-native browser automation built on WebDriver BiDi, shipped as a single Go binary that auto-downloads Chrome for Testing — pip install vibium and you are ready, no extra CSV dependency required since csv ships with Python. The pattern is two clean halves: Vibium extracts the table into Python lists, and csv.writer turns those lists into a comma-separated file any spreadsheet can open. findAll() returns a plain list, so you loop over rows exactly like a normal Python list, and Vibium auto-waits each element into the DOM so a lazy-loaded table will not race your script. Created by Jason Huggins, co-creator of Selenium and Appium, Vibium makes table-to-CSV a short, dependable script you can schedule and forget.
What is the table-to-CSV script?
import csv
from vibium import browser_sync as browser
vibe = browser.launch()
vibe.go("https://example.com/pricing")
# Read the header cells once.
headers = [th.text() for th in vibe.findAll("table thead th")]
# Read every body row and its cells.
row_count = len(vibe.findAll("table tbody tr"))
rows = []
for i in range(row_count):
selector = f"table tbody tr:nth-child({i + 1}) td"
rows.append([td.text() for td in vibe.findAll(selector)])
# Write it all to a CSV file.
with open("pricing.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(headers)
writer.writerows(rows)
print(f"Wrote {len(rows)} rows to pricing.csv")
vibe.quit()The script reads the header row, walks every body row with a :nth-child selector to scope cells to one row, then writes the headers and rows to pricing.csv with csv.writer.
How does each step work?
vibe.go(url)— opens the page and waits for the load event.vibe.findAll("table thead th")— returns a list of header cells;text()on each gives the column names.vibe.findAll("table tbody tr")— returns every row element; its length is the row count. A:nth-childselector then scopes the cell lookup to a single row.csv.writer(f)— Python's built-in CSV writer.writerow()writes the header;writerows()writes all data rows at once.vibe.quit()— shuts the browser down.
findAll() returns immediately and yields an empty list when nothing matches, so the script will not hang on an empty table. See Scrape a table with Vibium for the extraction step in detail.
How do I write labeled rows with DictWriter?
For a CSV keyed by column name, zip the headers against each row into dictionaries and write them with csv.DictWriter:
import csv
from vibium import browser_sync as browser
vibe = browser.launch()
vibe.go("https://example.com/pricing")
headers = [th.text() for th in vibe.findAll("table thead th")]
row_count = len(vibe.findAll("table tbody tr"))
records = []
for i in range(row_count):
selector = f"table tbody tr:nth-child({i + 1}) td"
values = [td.text() for td in vibe.findAll(selector)]
records.append(dict(zip(headers, values)))
with open("pricing.csv", "w", newline="") as f:
writer = csv.DictWriter(f, fieldnames=headers)
writer.writeheader()
writer.writerows(records)
vibe.quit()DictWriter keeps your CSV columns aligned to the header names even if the source table reorders its columns.
How do I handle a table that loads after the page?
If JavaScript renders the table after load, wait for the first row before reading, since findAll() resolves immediately and would return an empty list if called too early:
from vibium import browser_sync as browser
vibe = browser.launch()
vibe.go("https://example.com/pricing")
# Finding one row waits the table into the DOM.
vibe.find("table tbody tr")
row_count = len(vibe.findAll("table tbody tr"))
print(f"Table is ready with {row_count} rows")
vibe.quit()Because find() auto-waits on actionability, the single find() for one row guarantees the table exists before findAll() reads it.
Tips for clean CSV exports
- Always pass
newline=""toopen()so thecsvmodule does not insert blank rows on some platforms. - Use
encoding="utf-8"inopen()when cells contain accented characters or symbols. - Scope selectors to one table with an
idor class so a layout change elsewhere does not corrupt your export. - Write as you go for very large tables — flush each row inside the loop so a crash does not lose everything.
Next steps
Frequently asked questions
How do I export a scraped table to CSV with Vibium?
Scrape the table by reading rows with findAll() and each cell's text(), build a list of records, then write them to disk with Python's built-in csv module. Vibium handles the browser and extraction; csv.writer turns your rows into a clean comma-separated file you can open in any spreadsheet.
Do I need a library to write CSV from Vibium data?
No. Python's standard library includes the csv module, so you can write rows with csv.writer or labeled records with csv.DictWriter without installing anything. Vibium gives you the cell text as strings, which is exactly what the csv module expects to write.
How do I keep the header row when exporting to CSV?
Read the table's th cells once with findAll() to get the column names, write them as the first CSV row, then write each data row beneath. With csv.DictWriter you pass the headers as fieldnames and call writeheader() once before writing your record dictionaries.
Vibium is created by Jason Huggins. This is an independent tutorial — see the official Vibium site and GitHub repo for canonical docs.
Related guides
How to Automate a Checkout Flow with Vibium
Automate an e-commerce checkout with Vibium in Python — add to cart, fill shipping and payment fields, place the order, and verify the confirmation page.
4 min read→How-To RecipesHow to Automate a Google Search with Vibium
Automate a Google search with Vibium in Python — open Google, type a query, submit it, and read the result titles in about ten lines of code.
3 min read→How-To RecipesHow to Automate a Multi-Tab Flow with Vibium
Automate a multi-tab flow with Vibium in Python — open new tabs with new_page(), switch with bring_to_front(), capture popups, and close tabs cleanly.
3 min read→How-To RecipesHow to Automate a Search Box with Vibium
Automate a search box with Vibium in Python — find the input, type your query, press Enter, wait for results to render, and read them back with findAll.
3 min read→