Home > AI > Language > HTML >

Convert HTML to Excel

import pandas as pd
from html import unescape
import json
import os
from datetime import datetime


def extract_table_from_html(html_file):
    with open(html_file, 'r', encoding='utf-8') as file:
        html_string = file.read()

        dfs = pd.read_html(unescape(html_string))
        df = dfs[0]
        return df


filename = 'a'
html_file = f'{filename}.html'
df = extract_table_from_html(html_file)
df.to_excel(f'{filename}.xlsx', index=False)

Leave a Reply