本文主要是介绍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()
这篇关于python读取存入cookies信息实现登陆的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!