python与selenium自动化基础-cookies操作
selenium对cookies的操作
get_cookies() 获取所有cookies
get_cookie(key) 获取key对应的值
add_cookie(cookie_dict) 设置cookies
delete_cookie(name) 删除指定名称的cookie
delete_all_cookies() 删除所有cookie
from selenium import webdriver # 创建浏览器 driver = webdriver.Firefox() # 访问有道 url = 'http://www.youdao.com/' driver.get(url) # 获取cookies,直接调用,不需要参数 data = driver.get_cookies() print(data) # 删除所有cookies driver.delete_all_cookies() # 设置cookies cookie = {"name":"itcast","value":"soft_test"} driver.add_cookie(cookie) # 获取 data1 = driver.get_cookies() print(data1)
完