获取cookie

from selenium import webdriver
from time import sleep
dr = webdriver.Firefox()
dr.get('http://mail.163.com')
dr.implicitly_wait(5)
# 找到账号所在frame
ifra = dr.find_element_by_css_selector('div.loginUrs>iframe')
# 切换到账号所在frame
dr.switch_to.frame(ifra)
# dr.switch_to.frame(0)
account_input = dr.find_element_by_css_selector('.j-inputtext.dlemail')
passwd_input = dr.find_element_by_css_selector('.j-inputtext.dlpwd')
account_input.clear()
account_input.send_keys('********')
passwd_input.clear()
passwd_input.send_keys('******')
# 密码直接提交无法登录
# passwd_input.submit()
dr.find_element_by_css_selector('#dologin').click()
print('登录成功')
sleep(5)
# 切换到顶级页面
dr.switch_to.default_content()
# 获取到cookiese,这里的coo是list,但是实际内容是{'name':'sid','value':'abcdefg','zhangsan0':'lisi'}
coo = dr.get_cookies()
print(coo)

for v in coo:
    # 可以通过这种方式的到真正的cookiese
    # coo_dict[coo['name']] = coo['value']
    print(v['name'],v['value'])

 

posted @ 2019-03-21 23:18  唐大侠的小迷弟  阅读(154)  评论(0编辑  收藏  举报