当前位置:   article > 正文

Python selenium 操作当前页面的cookies信息_python selenium获取cookie

python selenium获取cookie

学习笔记~

from selenium import webdriver
from selenium.webdriver.common import keys
from selenium.webdriver.common.by import By
import time
from selenium.webdriver import ActionChains
from selenium.webdriver.support.select import Select

driver = webdriver.Chrome()

# ===============模拟操作cookies====================
driver.get('https://baidu.com/')

# 1.获取cookies信息
cs = driver.get_cookies()
print(cs)
# 单独获取某个cookies
cv = driver.get_cookie("ZFY")
print(cv)

# 2添加cookeis信息
cookie = {"name": "aaa", "value": "bbb"}
driver.add_cookie(cookie)

print(driver.get_cookie("aaa"))

# 3.删除cookies信息

driver.delete_cookie("aaa")

print(driver.get_cookie("aaa"))

time.sleep(2)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/608359
推荐阅读
相关标签
  

闽ICP备14008679号