import xlwt
from QD_project.common.base_page import basepage #已经封装好的浏览器基础信息
class Test_Cookies:
def Write_workbook(self):
self.drives = basepage.open_url() #打开对应的浏览器地址,
basepage.set_browser_max()
basepage.wait(40) #输入账号密码
cookies = self.drives.get_cookies() #获取相关的cookies信息
workbook = xlwt.Workbook(encoding='utf-8') # 创建workbook对象
worksheet = workbook.add_sheet('sheet1') # 创建sheet表
worksheet.write(0, 0, 'name')
worksheet.write(0, 1, 'value')
worksheet.write(0, 2, 'path')
worksheet.write(0, 3, 'domain')
worksheet.write(0, 4, 'httpOnly')
worksheet.write(0, 5, 'secure') #存入cookies字段
for i in range(1, len(cookies)+1): #表头0行是字段名,从第二行开始,到最后+1涵盖最后一个
worksheet.write(i, 0, cookies[i - 1]['name'])
worksheet.write(i, 1, cookies[i - 1]['value'])
worksheet.write(i, 2, cookies[i - 1]['path'])
worksheet.write(i, 3, cookies[i - 1]['domain'])
worksheet.write(i, 4, cookies[i - 1]['httpOnly'])
worksheet.write(i, 5, cookies[i - 1]['secure'])
workbook.save('test_cookies.xls') #对应的cookies字段存入对应的表格,保存获取到的cookies信息
if __name__ =='__main__':
Test_Cookies().Write_workbook()