添加删除cookie 一般用到三种:
get_cookeis() 获取cookie
add_cookie() 添加cookie
delete_cookie() 删除指定cookie
delete_all_cookies() 删除所有cookie
如下:
from selenium import webdriver
driver=webdriver.Chrome()
driver.get("http://www.baidu.com")
Obtain=driver.get_cookies() # 获取cookie
print(Obtain)
Obtain1=driver.add_cookie({'name':'A_AA_AAAAA','value':'1111_11111_00000_22222_33333_44444'}) # 添加cookie
for cookie in driver.get_cookies():
print("%s -> %s "% (cookie['name'],cookie['value'])) #遍历打出所有cookie
print("_________________________________________________________________")
driver.delete_cookie("CookieName") #删除添加的cookie
print("_________________________________________________________________")
driver.delete_all_cookies() # 删除所有的cookie