qq_40173895 2021-06-21 15:02 采纳率: 100%
浏览 90
已采纳

Invalid argument之前还能运行的,重启之后就这样了

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")

 

  • 写回答

3条回答 默认 最新

  • CSDN专家-HGJ 2021-06-21 15:11
    关注

    路径写错了不是双斜杠,要写成这样:D:/data/wcdma_b1.xls。workbook参数传递错误,Workbook函数没有文件路径参数,语法是class xlwt.Workbook.Workbook(encoding='ascii', style_compression=0)。将第26行改成book = xlwt.Workbook()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度