读取cookie:
读取所有cookie:get_cookies()
读取指定cookie:get_cookie(name)
添加cookie:add_cookie(dict)
删除cookie:
删除所有cookie:delete_all_cookies()
删除指定cookie:delete_cookie(name)
coding=utf-8
from selenium import webdriver
dr = webdriver.Firefox()
dr.get("https://passport.bilibili.com/login")
dr.add_cookie({ u'name': u'zhangsan', u'value': u'zhangsan1234'}) #新增张三的cookie
按指定格式打印
for cookie in dr.get_cookies():
print "%s/%s" % (cookie['name'],cookie['value'])
dr.delete_cookie( u'zhangsan') #指定删除张三的cookie
print '--after delete cookies--'
for cookie in dr.get_cookies():
print "%s/%s" % (cookie['name'],cookie['value'])
dr.quit()
返回结果sid/hw6452jw
finger/964b42c0
buvid3/1DB418E1-9AE4-49BA-8E1A-3C099020275D13519infoc
zhangsan/zhangsan1234 #新增的张三cookie
--after delete cookies--
sid/hw6452jw
finger/964b42c0
buvid3/1DB418E1-9AE4-49BA-8E1A-3C099020275D13519infoc