Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2. from openpyxl import load_workbook
  3. import xlwt
  4.  
  5. # Initialize a workbook
  6. book = xlwt.Workbook()
  7.  
  8. # Add a sheet to the workbook
  9. sheet1 = book.add_sheet("Лог")
  10.  
  11. # The data
  12. cols = ["ID", "Nick_Name", "Фракция", "Текст", "Время"]
  13.  
  14.  
  15.     with open("bank.html", "r", encoding="utf-8") as f:
  16.        
  17.         contents = f.read()
  18.      
  19.         soup = BeautifulSoup(contents, 'lxml')
  20.      
  21.         tags = soup.find_all(['th', 'tr'])
  22.        
  23.         for tag in tags:
  24.  
  25. txt = tag.text.split()
  26.  
  27. # Loop over the rows and columns and fill in the values
  28. for num in range(50):
  29.       row = sheet1.row(num)
  30.       for index, col in enumerate(cols):
  31.           value = txt[index]
  32.           row.write(index, value)
  33.  
  34. # Save the result
  35. book.save("test.xls")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement