import xlwt
import os
from bs4 import BeautifulSoup
lists = [152, 154, 156, 158]
file_path = "d://cal/"
print(file_path)
#for filename in os.listdir(file_path):
for filename in os.listdir(r"d://cal/"):
f = open(file_path + filename)
file_name = f.name
print(file_name)
with open(file_name, 'r') as file:
soup = BeautifulSoup(file, features='lxml')
tables_list = soup.find_all('table')
for num in range(0, len(lists)):
table = tables_list[lists[num]].get_text()
my_str = table
my_str = my_str.replace("\n", "^")
my_str = my_str.replace("^^^", "\n")
f1 = open(r"d://data/wcdma_b1.txt", 'a')
f1.write(my_str)
f1.close()
txt_path = r"d://data/wcdma_b1.txt"
print(txt_path)
# return txt_path
book = xlwt.Workbook(r"d://data/wcdma_b1.xls", style_compression=0)
sheet = book.add_sheet('data', cell_overwrite_ok=0)
sheet.write(0, 0, 'Frequency')
sheet.write(0, 1, 'AGC_Offset')
sheet.write(0, 2, 'AGC_Offset_Min')
sheet.write(0, 3, 'AGC_Offset_Max')
with open(txt_path, 'r+') as fd:
n = 1
for text in fd.readlines():
frequency = text.split('^')[0]
agc_offset = text.split('^')[3]
agc_offset_min = text.split('^')[4]
agc_offset_max = text.split('^')[5]
sheet.write(n, 0, frequency)
sheet.write(n, 1, agc_offset)
sheet.write(n, 2, agc_offset_min)
sheet.write(n, 3, agc_offset_max)
n = n + 1
book.save("d://data/wcdma_b1.xls")