python selenium 使用cookies跳过登录
注意点:
1.需要先访问下地址,driver.get(url)
2.cookie可以用抓包工具抓登录后的cookie
3.cookie是字典格式
4.多个cookie用for语句添加
# coding:utf-8
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.maximize_window()
driver.get(url)
# # 添加cookie
cookies = dict(user_token='2222',PHPSESSID='1111')
for k,v in cookies.items():
driver.add_cookie({'name':k,'value':v})
time.sleep(3)
# 刷新下页面
driver.refresh()
time.sleep(3)