Convert HTML Table Into CSV File in Python
Convert HTML Table Into CSV File in Python
geeksforgeeks.org/convert-html-table-into-csv-file-in-python/
April 2, 2020
CSV file is a Comma Separated Value file that uses a comma to separate values. CSV
file is a useful thing in today’s world when we are talking about machine learning, data
handling, and data visualization. In this article, we will discuss how to convert an HTML
table into a CSV file.
HTML table can be converted to CSV file using BeautifulSoup and Pandas module of
Python. These modules do not comes built-in with Python. To install them type the below
command in the terminal.
Python3 Code for converting the HTML table into CSV file
import os
1/4
import sys
import pandas as pd
path = 'html.html'
# empty list
data = []
list_header = []
try :
list_header.append(items.get_text())
except :
continue
sub_data = []
try :
sub_data.append(sub_element.get_text())
except :
2/4
continue
data.append(sub_data)
# DataFrame
dataFrame.to_csv( 'Geeks.csv' )
Output:
Attention geek! Strengthen your foundations with the Python Programming Foundation
Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with
the Python DS Course. And to begin with your Machine Learning Journey, join the
Machine Learning – Basic Level Course
Article Contributed By :
3/4
SohelRaja
@SohelRaja
Vote for difficulty
Report Issue
4/4