python 将cookie写入excel并读取

# — coding: utf-8 –# @Time : 2022/6/20 11:05import xlrd, xlwt, osexcel_path = os.path.join(os.path.abspath(__file__), “../data/zentao_login_cookies.xlsx”)class ExcelUtils: def __init__(self, excel_path=excel_path): self.excel_path = excel_path def write_excel(self): wb = xlwt.Workbook() sheet = wb.add_sheet(‘zentao_cookies’) row_list = [[“name”, “value”, “Domain”, “path”], [‘zentaosid’, ‘l97vmm6ovptiq8c47s6unb2e31’, ‘xx.107.178.45’, ‘/’], [‘theme’, ‘default’, ‘xx.107.178.45’, ‘/zentao/www/’], [‘device’, ‘desktop’, ‘xx.107.178.45’, ‘/zentao/www/’], [‘lang’, ‘zh-cn’, ‘xx.107.178.45’, ‘/zentao/www/’]] for i in range(0, len(row_list)): data = row_list[i] for j in range(0, len(data)): sheet.write(i, j, data[j]) wb.save(self.excel_path) def read_excel(self): wk = xlrd.open_workbook(self.excel_path) sheet = wk.sheet_by_name(“zentao_cookies”) rows = sheet.nrows cols = sheet.ncols cookies_list = [] for i in range(cols + 1): cookie_list = [] for j in range(rows – 1): cookie_list.append(sheet.cell_value(i, j)) cookies_list.append(cookie_list) return cookies_list def list_to_change_dic(self): c= [] for i in range(0, 4): b = [] for j in range (1,5): a = {self.read_excel()[0][j-1]: self.read_excel()[i+1][j-1]} b.append(a) c.append(b) return cif __name__ == ‘__main__’: ecl_util = ExcelUtils() # ecl_util.write_excel() # ecl_util.read_excel() # for i in range(0,4): # print(ecl_util.list_to_change_dic()[0])

郑重声明:本文内容及图片均整理自互联网,不代表本站立场,版权归原作者所有,如有侵权请联系管理员(admin#wlmqw.com)删除。
上一篇 2022年6月23日 06:24
下一篇 2022年6月23日 06:24

相关推荐

联系我们

联系邮箱:admin#wlmqw.com
工作时间:周一至周五,10:30-18:30,节假日休息