语法:
1.获取所有的cookie:driver.get_cookies()
2.添加cookie:ass_cookie(cookie值)
案例:
from selenium import webdriver
from time import sleep
driver = webdriver.Chrome()
url = "http://www.baidu.com/"
driver.get(url)
cookies = driver.get_cookies()
for cookie in cookies:
print(cookie)
cookie_dict = {"name": "1114", "value": "28"}
driver.add_cookie(cookie_dict)
print("->" * 60)
cookies = driver.get_cookies()
for cookie in cookies:
print(f"name:{cookie.get('name')}, value:{cookie.get('value')}")
sleep(2)
driver.quit()