常用操作cookie的方法如下:
- get_cookie(name='aaa') 获取key(name)为aaa的cookie
- get_cookies() 获取所有cookie
- add_cookie(dict) 添加cookie
- delete_cookie(name='aaa') 删除cookie
- delete_all_cookies() 删除所有cookie
from selenium import webdriver driver = webdriver.Chrome() driver.get('https://www.baidu.com') cookies = driver.get_cookies() # 获取所有cookie cookie = driver.get_cookie(name='aaa') # 获取key(name)为aaa的cookie driver.add_cookie({'name':'aaa', 'value':'bbb'}) # 添加cookie driver.delete_cookie(name='aaa') # 删除名为aaa的cookie driver.delete_all_cookies() # 删除所有cookie