selenium4中 网页cookie的保存与读取
import json
from selenium import webdriver
driver = webdriver.Edge()
url = 'https://baidu.com'
driver.get(url)
保存当前网页的cookie
def savecks():
cookies = driver.get_cookies()
jscookies = json.dumps(cookies)
with open('tbcookies.txt','w') as f:
f.write(jscookies)
读取硬盘里保存的cookie
with open('tbcookies.txt','r',encoding='utf-8') as f:
cookielist = json.loads(f.read())
for cookie in cookielist:
driver.add_cookie(cookie)
driver.refresh()
标签:cookies,读取,driver,selenium4,json,cookie
From: https://www.cnblogs.com/Aldream/p/18196912