1 from selenium import webdriver 2 from selenium.webdriver.chrome.options import Options 3 4 5 browers_path = r'C:UsersAdministratorAppDataLocal360ChromeChromeApplication360chrome.exe' 6 chrome_option = Options() 7 chrome_option.binary_location = browers_path 8 browers_driver = webdriver.Chrome(options=chrome_option) 9 browers_driver.get("http://www.baidu.com") 10 cookie_list = browers_driver.get_cookies() 11 #获取所有cookie信息,返回的是一个列表 12 for i in cookie_list: 13 print(i) 14 print(30*'@') 15 a = browers_driver.get_cookie('BIDUPSID')#通过字典的键获取对应的cookie 16 print(a) 17 browers_driver.delete_cookie('BIDUPSID')#删除某个cookie 18 browers_driver.delete_all_cookies()#删除所有cookie