数据导入excel+一个镜像+ selenium证书验证问题

镜像网址

https://pypi.tuna.tsinghua.edu.cn/simple

网址证书验证

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('ignore-certificate-errors')
driver = webdriver.Chrome(chrome_options=options)

数据导入excel文件

import xlsxwriter as xw
#错误数据写入excel
def write_excel(list):
    wb = xw.Workbook(r"C:\Users\user\Desktop\text.xlsx")
    ws = wb.add_worksheet("错误数据汇总")
    # 表头heads,用于判断字典中的键值是否已存在
    heads = []
    # n用于确定行数,每循环到一个字典就加1
    n = 0
    for a in list:
        n += 1
        # 获取字典中的键
        for key in a.keys():
            # 判断每个键是否存在于heads,不存在则添加
            if key not in heads:
                heads.append(key)
                # 将key添加至excel作为列名
                ws.write(0, len(heads) - 1, key)
            # 写入excel。ws.write(行,列,值)
            ws.write(n, heads.index(key), str(a[key]))
    wb.close()
list1 = [{'姓名':'小红', '年龄':'10'}, {'姓名':'小白','年龄':'8','爱好':'唱歌跳舞'}]
write_excel(list1)
import xlrd
import xlutils
‘’‘
# 需要在xlutils文件里添加这个不添加容易找不到copy方法
from .compat import *
from .copy import *
from .display import *
from .filter import *
from .margins import *
from .save import *
from .styles import *
from .view import *
’‘’
def write_excel(self, data, jyz_name):
  file_name = next((item for item in self.fent_files_list if jyz_name in item), None)

  if not file_name:
      file_name = '通用版本.xls'
  files_path = os.path.join(self.fent_path, file_name)
  filename = jyz_name + datetime.now().today().strftime('%Y-%m') + '.xls'

  save_path = os.path.join(self.save_path, filename)
  xls = xlrd.open_workbook(files_path, formatting_info=True)  # 得到文件
  wbook = xlutils.copy(xls)  # 复制文件并保留格式
  wsheet = wbook.get_sheet(0)

  for row_index, row in enumerate(data):
      for col_index, cell_value in enumerate(row):
          if col_index == 4:
              col_index += 6
          elif col_index >= 5:
              col_index += 12
          wsheet.write(row_index + 2, col_index, cell_value)
  # 保存工作簿到指定路径的文件
  wbook.save(save_path)
  return save_path
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值