from bs4 import BeautifulSoup
from openpyxl import load_workbook
import xlwt
# Initialize a workbook
book = xlwt.Workbook()
# Add a sheet to the workbook
sheet1 = book.add_sheet("Лог")
# The data
cols = ["ID", "Nick_Name", "Фракция", "Текст", "Время"]
txt = []
with open("bank.html", "r", encoding="utf-8") as f:
contents = f.read()
soup = BeautifulSoup(contents, 'lxml')
tags = soup.find_all(['th', 'tr'])
for tag in tags:
txt.append(tag.text.split())
# Loop over the rows and columns and fill in the values
for i, vals in enumerate(txt):
row = sheet1.row(i)
for index, col in enumerate(cols):
value = vals[index]
row.write(index, value)
# Save the result
book.save("test.xls")