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
🌐
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 - In the next bit of code, we define a website that is simply the HTML for a table. We load it into BeautifulSoup and parse it, returning a pandas data frame of the contents. 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 dataframe).
Discussions

beautifulsoup - How to parse html table in python - Stack Overflow
I'm newbie in parsing tables and regular expressions, can you help to parse this in python: More on stackoverflow.com
🌐 stackoverflow.com
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
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
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
🌐
Practical Business Python
pbpython.com › pandas-html-table.html
Reading HTML tables with Pandas - Practical Business Python
The pandas read_html() function is useful for quickly parsing HTML tables in pages - especially in Wikipedia pages. By the nature of HTML, the data is frequently not going to be as clean as you might need and cleaning up all the stray unicode ...
🌐
ScraperAPI
scraperapi.com › home › blog › how to scrape html tables using python
How To Scrape HTML Tables Using Python
March 31, 2026 - Because all the employee data we’re looking to scrape is on the HTML file, we can use the Requests library to send the HTTP request and parse the respond using Beautiful Soup. Note: If you’re new to web scraping, we’ve created a web scraping in Python tutorial for beginners. Although you’ll be able to follow along without experience, it’s always a good idea to start from the basics. 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
🌐
Python
docs.python.org › 3 › library › html.parser.html
html.parser — Simple HTML and XHTML parser
Source code: Lib/html/parser.py This module defines a class HTMLParser which serves as the basis for parsing text files formatted in HTML (HyperText Mark-up Language) and XHTML. Example HTML Parser...
🌐
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
🌐
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 - Learn how to parse HTML tables in Python. Overcome challenges and extract data efficiently with top parsing tools.
🌐
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 ...
🌐
PyPI
pypi.org › project › html-table-parser-python3
html-table-parser-python3 · PyPI
This module consists of just one small class. Its purpose is to parse HTML tables without help of external modules. Everything I use is part of python 3.
      » pip install html-table-parser-python3
    
Published   Dec 06, 2022
Version   0.3.1
🌐
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
🌐
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
🌐
ZenRows
zenrows.com › homepage › tutorial › how to parse tables using beautifulsoup (+2 better ways)
How to Parse Tables Using BeautifulSoup (+2 better ways) - ZenRows
September 27, 2024 - We'll show you how to parse tables using BeautifulSoup. And you'll also learn two better ways to make the task easier. BeautifulSoup is mainly used to parse HTML in Python. The first step to parsing tables is to locate the table's HTML tag.
🌐
Bright Data
brightdata.com › blog › web-data › how-to-scrape-html-tables
Guide on How to Scrape HTML Tables With Python
September 16, 2025 - Collect all data presented in the table’s rows. To parse the content you collected, create a Beautiful Soup object: # Parse the HTML content using BeautifulSoup soup = BeautifulSoup(response.content, 'html.parser')
🌐
ProxiesAPI
proxiesapi.com › articles › parsing-html-tables-with-beautifulsoup
Parsing HTML Tables with BeautifulSoup | ProxiesAPI
from bs4 import BeautifulSoup import requests url = '<https://example.com/table>' resp = requests.get(url) soup = BeautifulSoup(resp.text, 'html.parser') table = soup.find('table') rows = [] for row in table.find_all('tr'): rows.append([val.text for val in row.find_all('td')])
🌐
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 - Response status code: 200 Content length: 37624 characters First 100 characters: <!DOCTYPE html> <html lang="en-US"> <head> <title>Python - Basic Operators - Tutorialspoint</title> Parse the HTML content and extract basic information ? # Parse the HTML content soup = BeautifulSoup(response.text, 'html.parser') # Extract page title title = soup.title.string print(f"Page title: {title}") # Find all heading tags that might precede tables headings = soup.find_all(['h2', 'h3', 'h4', 'h5', 'h6']) print(f"Found {len(headings)} heading tags") Page title: Python - Basic Operators - Tutorialspoint Found 9 heading tags ·
🌐
ScrapingAnt
scrapingant.com › blog › python-scrape-html-tables
Web Scraping HTML Tables with Python | ScrapingAnt
September 18, 2024 - This comprehensive guide delves into the intricacies of web scraping HTML tables using Python, providing both novice and experienced programmers with the knowledge and techniques needed to navigate this essential data collection method. We'll explore a variety of tools and libraries, each with its unique strengths and applications, enabling you to choose the most suitable approach for your specific scraping needs. From the versatile BeautifulSoup library, known for its ease of use in parsing HTML documents (Beautiful Soup Documentation), to the powerful Pandas library that streamlines table extraction directly into DataFrame objects (Pandas Documentation), we'll cover the fundamental tools that form the backbone of many web scraping projects.
🌐
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.
🌐
Reddit
reddit.com › r/python › guide to scrape html table using python
r/Python on Reddit: Guide to Scrape HTML Table Using Python
October 29, 2022 - Yeah...I stopped reading the second they equated <th> and <thead>, and then described them as defining a row. My man, have you ever created an HTML table? Edit: Here's a nice W3Schools refresher. ... Help required regarding both web scraping and using pandas to store data from a table in csv using python
🌐
Oxylabs
oxylabs.io › blog › python-scrape-tables
How to Web Scrape HTML Tables With Python: Step-by-Step
Once the response of the HTTP request is ready in the response variable, parse the content using the BeautifulSoup library. Then, you can use a unique CSS selector to extract the target table data from the parsed soup object: ... try: # Step ...