Pickle 保存和读取Cookie实现免登陆
from selenium import webdriver
from time import sleep
import pickle
import traceback
driver = webdriver.Firefox(r"E:\43j6ugol.d")
driver.get("https://wj.qq.com/")
sleep(40)
pickle.dump( driver.get_cookies(), open("cookies.pkl","wb"))
try:
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
print(cookie)
new_cookie = {}
new_cookie['name'] = cookie['name']
new_cookie['value'] = cookie['value']
driver.add_cookie(new_cookie)
except:
traceback.print_exc()