Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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", "Фракция", "Текст", "Время"]
- 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 = tag.text.split()
- # Loop over the rows and columns and fill in the values
- for num in range(50):
- row = sheet1.row(num)
- for index, col in enumerate(cols):
- value = txt[index]
- row.write(index, value)
- # Save the result
- book.save("test.xls")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement