import pickle
from selenium import webdriver
from time import sleep

def setup_method(self):
    url = "https://xueqiu.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)



↙↙↙阅读原文可查看相关链接,并与作者交流