Search
 
SCRIPT & CODE EXAMPLE
 

HTML

python snippet to convert html file to .csv file

# Importing the required modules 
import os
import sys
import pandas as pd
from bs4 import BeautifulSoup
   
path = 'html.html'
   
# empty list
data = []
   
# for getting the header from
# the HTML file
list_header = []
soup = BeautifulSoup(open(path),'html.parser')
header = soup.find_all("table")[0].find("tr")
  
for items in header:
    try:
        list_header.append(items.get_text())
    except:
        continue
  
# for getting the data 
HTML_data = soup.find_all("table")[0].find_all("tr")[1:]
  
for element in HTML_data:
    sub_data = []
    for sub_element in element:
        try:
            sub_data.append(sub_element.get_text())
        except:
            continue
    data.append(sub_data)
  
# Storing the data into Pandas
# DataFrame 
dataFrame = pd.DataFrame(data = data, columns = list_header)
   
# Converting Pandas DataFrame
# into CSV file
dataFrame.to_csv('Geeks.csv')
Comment

PREVIOUS NEXT
Code Example
Html :: step 47 freecodecamp nutrition table 
Html :: prop sent via link has no spaces vuejs 
Html :: continuous slider html 
Html :: x and y in javascript 
Html :: url to html converter 
Html :: html like symbol 
Html :: nativescript scrollview full height 
Html :: drupal to wordpress 
Html :: créer un titre html 
Html :: hirudhi map 
Html :: bootstrap admin prestashop tpl tabs 
Html :: see emoji flag on desktop 
Html :: servicenow g: breakpoint 
Html :: how to set up html basic workspace 
Html :: phpstrom goto bookmark 
Html :: freecodecamp step 3 quiz 
Html :: html entity 
Html :: accident news report 
Html :: how to detect what someone typed html code 
Html :: how to insert div inside input 
Html :: html type range show label 
Html :: what is mac cloudkit 
Html :: <meta name="theme-color" content="#9d4edd" 
Html :: where to keep index.html file in mac for running on apache server 
Html :: html shortcut 
Html :: Google Books Embedded Viewer API Example 
Html :: index number in odoo reports 
Html :: typo3 fluid form input text 
Html :: mise en forme 
Html :: How to Disable Auto Period Typing Shortcut on Mac 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =