python读取存入cookies信息实现登陆

import xlrd
from QD_project.common.base_page import basepage

class Test_get_Cookies:
def Red_workbook(self):
self.drives = basepage.open_url()
workbook = xlrd.open_workbook('test_cookies.xls') #读取封装好的cookies信息
sheet = workbook.sheet_by_name('sheet1') #读取表头信息
cookies_list = [] #创建列表存放cookies信息
for row_num in range(1,sheet.nrows): #遍历列表行数
cookies_dict = {} #创建字典,遍历数据存放【以下是列数遍历】
cookies_dict['name'] = sheet.cell_value(row_num,0)
cookies_dict['value'] = sheet.cell_value(row_num, 1)
cookies_dict['path'] = sheet.cell_value(row_num, 2)
cookies_dict['domain'] = sheet.cell_value(row_num, 3)
cookies_dict['httpOnly'] = bool(sheet.cell_value(row_num, 4))
cookies_dict['secure'] = bool(sheet.cell_value(row_num, 5))
cookies_list.append(cookies_dict) #key:value数据存放列表
for cookie in cookies_list: #循环遍历存入cookies信息登陆
self.drives.add_cookie(cookie)
basepage.wait(5)
self.drives.refresh()



if __name__ == '__main__':
Test_get_Cookies().Red_workbook()
上一篇:postman使用教程13-cookies 管理器


下一篇:vue前端,付款功能跳转支付宝