开发者

Retrieve the contents of cookies using Java

开发者 https://www.devze.com 2023-03-06 13:37 出处:网络
I need to retrieve the properties of the cookies stored upon visiting a web page. Specifically, Name Host

I need to retrieve the properties of the cookies stored upon visiting a web page. Specifically,

  1. Name
  2. Host
  3. Expiration Date

Is t开发者_如何学Gohere a library that I can use?

EDIT: I apologize for the lack of detail.. I am employing Selenium to retrieve the WEB page. Asserting the presence of the cookie (and ultimately deleting it) is present in Selenium's native functionality. Reading the contents, however, is something I was hoping to do...


You can use

selenium.getCookieByName("CookieName")

to read the cookie by its name. This returns the cookie value as String

selenium.getCookie()

to get all the cookies in the page. You can assign this to a string and read it.

Finally to delete it you can use :

selenium.deleteCookie("CookieName")


Here is an excellent resource I stumbled upon, using the java.net API - http://www.hccp.org/java-net-cookie-how-to.html


For cookie handling use WebDrive manage() e.g. get cookie's value as string

driver.manage().getCookieNamed(cookieName).getValue();
0

精彩评论

暂无评论...
验证码 换一张
取 消