Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Selenium Learning: operating Cookie

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report