html文件转换成excel

path_html = str(path_f)  # 原来的html文件
file_name = str(os.path.basename(path_f)).split('.')[0]
new_excel_path = os.getcwd() + '\\' + file_name
io = str(new_excel_path + '.xlsx')  # 新的excel文件
new_io = io
# pandas html转excel
# f = open(path_html, 'r', encoding='utf-8')
f = open(path_html, 'r', encoding='GB2312')
# f = open(path_html, 'r', encoding='GBK')
html = f.read()
df = pd.read_html(html)
bb = pd.ExcelWriter(io, dtype=str)
df[0].to_excel(bb)
bb.close()

 

posted @ 2021-04-09 10:40  拷贝达人  阅读(1395)  评论(0编辑  收藏  举报