DEV Community

Python Tools Lab
Python Tools Lab

Posted on

Extract Any HTML Table to Excel in 3 Lines of Python

You don't need complex regex or nested BeautifulSoup loops to scrape financial, sports, or statistics tables.

With pandas, you can extract every HTML table on a webpage in 3 lines of code:

import pandas as pd
tables = pd.read_html("https://en.wikipedia.org/wiki/List_of_countries_by_GDP_(nominal)")
tables[0].to_excel("gdp_data.xlsx", index=False)
Enter fullscreen mode Exit fullscreen mode




Want More Production-Ready Scraping Templates?

If you need full scripts for static catalogs, dynamic JavaScript/Playwright scrolling, and anti-block User-Agent rotation, check out The No-BS Python Web Scraping Playbook (50% launch discount):

Download the Playbook & 4 Templates: https://tugrulian8.gumroad.com/l/ktiqff/LAUNCH50

Top comments (0)