web自动化存cookie和读取cookie

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)


你可能感兴趣的:(web自动化存cookie和读取cookie)