You should use some HTML parsing library like lxml:

from lxml import etree
s = """<table>
  <tr><th>Event</th><th>Start Date</th><th>End Date</th></tr>
  <tr><td>a</td><td>b</td><td>c</td></tr>
  <tr><td>d</td><td>e</td><td>f</td></tr>
  <tr><td>g</td><td>h</td><td>i</td></tr>
</table>
"""
table = etree.HTML(s).find("body/table")
rows = iter(table)
headers = [col.text for col in next(rows)]
for row in rows:
    values = [col.text for col in row]
    print dict(zip(headers, values))

prints

{'End Date': 'c', 'Start Date': 'b', 'Event': 'a'}
{'End Date': 'f', 'Start Date': 'e', 'Event': 'd'}
{'End Date': 'i', 'Start Date': 'h', 'Event': 'g'}
Answer from Sven Marnach on Stack Overflow
🌐
ZenRows
zenrows.com › homepage › tutorial › how to parse html tables using python + top 3 parsers
How to Parse HTML Tables Using Python + Top 3 Parsers - ZenRows
September 12, 2024 - Cool! You've just scraped an HTML table with BeautifulSoup in Python. However, a simpler way to achieve this task with less coding is to use a web scraping API like ZenRows. You'll see how it works in the next section. Parsing tables with ZenRows is a straightforward process.
Discussions

Any way to parse HTML tables?
You can probably find some JavaScript routine that can convert html table data to json. Then run the JavaScript in a URL action. I saw this ability to run JavaScript here and tried it out yesterday: https://www.reddit.com/r/shortcuts/comments/9hpplv/is_it_possible_to_read_the_contents_of_an_xml_file/?st=JNYO7T87&sh=bf71ea97 But just saw that Pretty Print also does this: https://www.reddit.com/r/shortcuts/comments/9mk9br/pretty_print_dictionary/?st=JNYOAYQW&sh=0a9cdf3d More on reddit.com
🌐 r/shortcuts
10
4
November 1, 2018
How to scrap a html table with bs4?
See how to write csv https://realpython.com/python-csv/ Altough I would create a loop on each tr and on each of those loop on each td for tr in soup.find_all("tr"): for td in tr.find_all("td"): handle td.text You might also want to consider pandas here https://www.geeksforgeeks.org/convert-html-table-into-csv-file-in-python/ More on reddit.com
🌐 r/learnpython
14
0
October 23, 2020
Guide to Scrape HTML Table Using Python
1.5M subscribers in the Python community. The largest Python community for Reddit! Stay up to date with the latest news, packages, and meta… More on reddit.com
🌐 r/Python
5
21
October 29, 2022
How to read a table in beautiful soup, and parse the elements
tables=soup.findAll('table')[0].findAll('tr') findAll('table') gets you list of tables. [0] is indexing the first item in the list. You could loop through each table: for table in soup.findAll('table'): or use pandas pandas has a read_html function - you could also try: tables = pandas.read_html(page.content) It returns a list of dataframes - one per table found. More on reddit.com
🌐 r/learnpython
12
2
January 5, 2022
People also ask

What are the best tools to scrape HTML tables?

Some of the best tools for scraping HTML tables include Python libraries like BeautifulSoup and Pandas. These tools allow you to easily extract table data and manipulate it. For more complex scenarios, Scraping APIs like ScraperAPI can handle dynamic content and bypass anti-scraping measures.

🌐
scraperapi.com
scraperapi.com › home › blog › how to scrape html tables using python
How To Scrape HTML Tables Using Python
What kind of data can HTML tables contain?

HTML tables can contain a wide variety of data types. They are commonly used to display structured information such as text, numbers, dates, images, links, and even nested tables. This makes them suitable for representing data like financial reports, product listings, and statistical data – which we can then scrape for analysis.

🌐
scraperapi.com
scraperapi.com › home › blog › how to scrape html tables using python
How To Scrape HTML Tables Using Python
How Can I Scrape Dynamic Tables?

To scrape dynamic tables that are generated or updated using JavaScript, you need tools that can render JavaScript content. Tools like ScraperAPI can fetch the fully loaded page, allowing you to extract the dynamic table data. Alternatively, you can use webdrivers like Selenium or PlayWright, which can simulate a real user interacting with the browser, loading dynamic content before scraping.

🌐
scraperapi.com
scraperapi.com › home › blog › how to scrape html tables using python
How To Scrape HTML Tables Using Python
🌐
Python
docs.python.org › 3 › library › html.parser.html
html.parser — Simple HTML and XHTML parser
This parser does not check that end tags match start tags or call the end-tag handler for elements which are closed implicitly by closing an outer element. Changed in version 3.4: convert_charrefs keyword argument added. Changed in version 3.5: The default value for argument convert_charrefs is now True. Changed in version 3.14.1: Added the scripting parameter. As a basic example, below is a simple HTML parser that uses the HTMLParser class to print out start tags, end tags, and data as they are encountered:
🌐
PyPI
pypi.org › project › html-table-parser-python3
html-table-parser-python3 · PyPI
A small and simple HTML table parser not requiring any external dependency.
      » pip install html-table-parser-python3
    
Published   Dec 06, 2022
Version   0.3.1
🌐
Practical Business Python
pbpython.com › pandas-html-table.html
Reading HTML tables with Pandas - Practical Business Python
In this article, I will discuss how to use pandas read_html() to read and clean several Wikipedia HTML tables so that you can use them for further numeric analysis. For the first example, we will try to parse this table from the Politics section on the Minnesota wiki page.
🌐
Tchut-Tchut Blog
beenje.github.io › blog › posts › parsing-html-tables-in-python-with-pandas
Parsing HTML Tables in Python with pandas | Tchut-Tchut Blog
March 27, 2018 - --------------------------------------------------------------------------- HTTPError Traceback (most recent call last) <ipython-input-17-7e6b50c9f1f3> in <module>() ----> 1 pd.read_html('https://httpbin.org/basic-auth/myuser/mypasswd') ~/miniconda3/envs/jupyter/lib/python3.6/site-packages/pandas/io/html.py in read_html(io, match, flavor, header, index_col, skiprows, attrs, parse_dates, tupleize_cols, thousands, encoding, decimal, converters, na_values, keep_default_na) 913 thousands=thousands, attrs=attrs, encoding=encoding, 914 decimal=decimal, converters=converters, na_values=na_values, -->
Find elsewhere
🌐
Finxter
blog.finxter.com › how-to-parse-html-table-using-python
How to Parse an HTML Table in Python? – Be on the Right Side of Change
November 14, 2021 - In this method, we will use the HTMLTableParser module to scrap HTML Table exclusively. This one doesn’t need any other external module. This module works only in Python 3 version. Install the HTMLTableParser and urllib.request using the command: pip install html-table-parser-python3 pip install urllib3
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-parse-html-pages-to-fetch-html-tables-with-python
How to Parse HTML pages to fetch HTML tables with Python?
November 9, 2020 - Status code: {response.status_code}") return [] # Parse HTML content soup = BeautifulSoup(response.text, 'html.parser') # Find all tables tables = soup.find_all('table') extracted_tables = [] for i, table in enumerate(tables): try: # Convert to DataFrame df = pd.read_html(str(table))[0] extracted_tables.append({ 'table_index': i + 1, 'dataframe': df, 'shape': df.shape }) except Exception as e: print(f"Error processing table {i + 1}: {e}") return extracted_tables # Example usage url = "https://www.tutorialspoint.com/python/python_basic_operators.htm" all_tables = extract_tables_from_url(url) print(f"Successfully extracted {len(all_tables)} tables") for table_info in all_tables[:2]: # Show first 2 tables print(f"\nTable {table_info['table_index']} - Shape: {table_info['shape']}") print(table_info['dataframe'].head(3))
🌐
ScraperAPI
scraperapi.com › home › blog › how to scrape html tables using python
How To Scrape HTML Tables Using Python
March 31, 2026 - Although you’ll be able to follow ... Let’s create a new directory for the project named python-html-table, then a new folder named bs4-table-scraper and finally, create a new python_table_scraper.py file.54...
🌐
Scott Rome
srome.github.io › Parsing-HTML-Tables-in-Python-with-BeautifulSoup-and-pandas
Parsing HTML Tables in Python with BeautifulSoup and pandas
May 30, 2016 - As you can see, we grab all the tr elements from the table, followed by grabbing the td elements one at a time. We use the “get_text()” method from the td element (called a column in each iteration) and put it into our python object representing a table (it will eventually be a pandas ...
🌐
PyPI
pypi.org › project › html-table-extractor
html-table-extractor · PyPI
from html_table_extractor.extractor import Extractor table_doc = """ <table><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></table> """ extractor = Extractor(table_doc, transformer=int) extractor.parse() extractor.return_list()
      » pip install html-table-extractor
    
Published   May 01, 2020
Version   1.4.1
🌐
Bright Data
brightdata.com › blog › web-data › how-to-scrape-html-tables
Guide on How to Scrape HTML Tables With Python
September 16, 2025 - # Parse the HTML content using BeautifulSoup soup = BeautifulSoup(response.content, 'html.parser') Next, locate the table element in the HTML with the id attribute "example2".
🌐
Zyte
zyte.com › home › blog › how to extract data from html table
How to extract data from an HTML table - Zyte #1 Web Scraping Service
September 13, 2022 - One such method is available in the popular python Pandas library, it is called read_html(). The method accepts numerous arguments that allow you to customize how the table will be parsed. You can call this method with a URL or file or actual string. For example, you might do it like this:
🌐
ProxiesAPI
proxiesapi.com › articles › parsing-html-tables-with-beautifulsoup
Parsing HTML Tables with BeautifulSoup | ProxiesAPI
BeautifulSoup is a useful library for extracting data from HTML tables in Python. With a few simple lines of code, you can parse an HTML table and convert it into a pandas DataFrame for further analysis.
🌐
GitHub
github.com › finxter › How-to-parse-HTML-Table-using-Python-
GitHub - finxter/How-to-parse-HTML-Table-using-Python-
Complete article: https://blog.finxter.com/how-to-parse-html-table-using-python/
Author   finxter
🌐
GitHub
github.com › schmijos › html-table-parser-python3
GitHub - schmijos/html-table-parser-python3: A small and simple HTML table parser not requiring any external dependency.
./html_table_converter -u http://web.archive.org/web/20180524092138/http://metal-train.de/index.php/fahrplan.html -o metaltrain · If you need help for the supported parameters append -h: ... A set of rudimentary tests have been implemented using Python's built-in unittest framework.
Starred by 86 users
Forked by 44 users
Languages   Python 66.3% | HTML 33.7% | Python 66.3% | HTML 33.7%
🌐
ScrapingBee
scrapingbee.com › blog › python-html-parsers
How to parse HTML in Python: A step-by-step guide for beginners | ScrapingBee
January 16, 2026 - Want to parse HTML in Python right away? Here's the fastest working setup: one version using plain old requests for static pages, and another using ScrapingBee for the real world, where sites throw JavaScript and anti-bot nonsense at you. ... import requests from bs4 import BeautifulSoup # Fetch the page directly url = "https://example.com" html = requests.get(url).text # Parse the HTML with BeautifulSoup + lxml soup = BeautifulSoup(html, "lxml") # Extract the title and all links print(soup.title.get_text()) for link in soup.select("a[href]"): print(link["href"])
🌐
AskPython
askpython.com › home › how to read html tables using python?
How to read HTML tables using Python? - AskPython
January 18, 2023 - Sometimes, you might want the data types of some columns from the table to be of a specific type. In such cases, you can typecast them using the read_html() function. Recall that in the above example, the data type of ‘Salary’ was ‘int64’.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.read_html.html
pandas.read_html — pandas 3.0.3 documentation - PyData |
The default value will return all tables contained on a page. This value is converted to a regular expression so that there is consistent behavior between Beautiful Soup and lxml. flavor{“lxml”, “html5lib”, “bs4”} or list-like, optional · The parsing engine (or list of parsing engines) to use.
🌐
Tutorials24x7
tutorials24x7.com › python › how-to-scrape-html-tables-using-python
How to Scrape HTML tables using Python? | Tutorials24x7
March 18, 2024 - We all know that the tables are built using the tags <table>, <th> or <thead>, <tbody>, <tr>, <td>. Though many developers respect these conventions while building a table, some don't follow them, making such projects harder than others. Python comes as a saviour here. We take the page- https://datatables.net/examples/styling/stripe.html to practice scraping tabular data with Python. Let's scrape using the requests library to send the HTTP request and parse the response using Beautiful Soup.