import pickle
from selenium import webdriver
from time import sleep
def setup_method(self):
url = "https://qq.com/"
self.driver = webdriver.Chrome()
self.driver.get(url)
def test_save_cookies():
sleep(15) #手动登录一次存cookie到pkl文件内
pickle.dump(driver.get_cookies(), open("cookies.pkl","wb"))
def load_cookies():
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
driver.add_cookie(cookie)
网友评论