from selenium import webdriverdriver = webdriver.Firefox()driver.get('http://www.baidu.com')cookies = driver.get_cookies()print(cookies)driver.delete_all_cookies()cookies = driver.get_cookies()print(cookies)cookie = [{ 'name': 'abc', 'value': 'def'}, { 'name': '123', 'value': '456'}]for d in cookie: driver.add_cookie({ 'domain': '.baidu.com', 'name': d['name'], 'value': d['value'], 'path': '/', 'expires': None })cookies = driver.get_cookies()print(cookies)
最后一个print输出
[{ 'expiry': None, 'value': 'def', 'httpOnly': False, 'domain': '.baidu.com', 'path': '/', 'secure': False, 'name': 'abc'}]