Prompt
How do I extract table data from websites that only show it in HTML?
Latest observation
Oct 14, 2026
OpenAI APIWeb search: off
If the data is already in the page’s HTML, you can usually extract it with a scraper by requesting the page and parsing the table tags.
Common approach
-
Fetch the HTML
- Use
requestsin Python orfetch/axiosin JavaScript.
- Use
-
Parse the HTML
- Use
BeautifulSoup(Python),lxml, or browser DOM parsing.
- Use
-
Locate the table
- Find
<table>,<tr>,<th>, and<td>elements.
- Find
-
Extract rows/cells
- Convert them into a list, CSV, or DataFrame.
Python example with BeautifulSoup
import requests
from bs4 import BeautifulSoup
url = "https://example.com/page-with-table"
html = requests.get(url).text
soup = BeautifulSoup(html, "html.parser")
table = soup.find("table")
rows = []
for tr in table.find_all("tr"):
cells = tr.find_all(["th", "td"])
row = [cell.get_text(strip=True) for cell in cells]
rows.append(row)
for row in rows:
print(row)
Python example with pandas
If the table is well-formed HTML, pandas can do a lot of the work:
import pandas as pd
url = "https://example.com/page-with-table"
tables = pd.read_html(url)
df = tables[0] # first table on the page
print(df)
This is often the easiest option.
If the table is loaded by JavaScript
Sometimes the HTML source doesn’t include the data directly, and it’s loaded after page load. In that case:
- Inspect the page network requests in browser dev tools
- Look for an API endpoint returning JSON
- Or use a browser automation tool like:
- Selenium
- Playwright
Tips
- Check the page source first to see whether the data is actually in the HTML.
- Handle pagination if the table spans multiple pages.
- Be careful with website terms of service and robots rules.
- Add headers/user-agent if the site blocks simple requests.
If you want, I can show you how to extract a specific table from a real URL in Python or JavaScript.