Selenium Learning: operating Cookie
File name: test14.py
# coding=utf-8from selenium import webdriverimport time,osdriver = webdriver.Chrome () driver.get ("http://www.baidu.com")# gets cookie information cookie = driver.get_cookies () # prints the obtained cookies information print (cookie) driver.get (" http://www.youdao.com")driver.add_cookie({'name': 'key-aaaaaaa' ") 'value':' value-bbbbbb'}) for cookie in driver.get_cookies (): print ("% s->% s"% (cookie ['name'], cookie [' value'])) time.sleep (3) driver.quit ()
The method of operating cookie by WebDriver
Get_cookies () gets all the cookies information
Get_cookie (name) returns the cookie information of the dictionary whose key is' name'
Add_cookie (cookie_dict) add cookie. "cookie_dict" refers to the dictionary object, which must have name and value values.
Delete_cookie (name,optionString): delete cookiexinxi, 'name' is the name of the cookie to be deleted, "optionString" is the option for this cookie, and currently supported options include "path" and "domain"
Delete_all_cookies () deletes all cookie information