How to get a value of a cookie provided a cookie jar?
See original GitHub issueIt is not entirely clear from the documentation how to get a value of a specific cookie provided an instance of a CookieJar
.
// This always gives me a single item array.
// It is not clear from the documentation when the result would contain more than entry.
const cookies = jar.getCookiesSync(guide.result.url);
> [ Cookie="ASP.NET_SessionId=gqwdcucn4iqdztwcvqr3xmpy; Expires=Wed, 17 Mar 2027 16:00:50 GMT; Domain=foo.com; Path=/; HttpOnly; HttpOnly,SC_ANALYTICS_GLOBAL_COOKIE=4e3659e87284422c8dd691f35b1a622e|False; HttpOnly,UserSessionId=af5abf42-e3c9-4478-a1c7-61300614dc8c|10002|181845|161471|2017-03-17; hostOnly=false; aAge=0ms; cAge=2ms" ]
// This is supposed to parse the cookie-string into a `Cookie` object.
Cookie.parse(cookies[0]);
Using Cookie.parse
in the above example I am getting an error:
TypeError: str.trim is not a function at Function.parse (/Users/gajus/Documents/dev/foo/node_modules/tough-cookie/lib/cookie.js:325:13) at exports.scrapeTickets (/Users/gajus/Documents/dev/applaudience/foo/src/countries/foo.js:122:23) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Get cookie from CookieJar by name - python - Stack Overflow
Yes, the __iter__ method will go through each cookie in CookieJar . for cookie in cj: print cookie.name, cookie.value, cookie.domain #etc ...
Read more >http.cookiejar — Cookie handling for HTTP clients — Python ...
The http.cookiejar module defines classes for automatic handling of HTTP cookies. It is useful for accessing web sites that require small pieces of...
Read more >CookieJar in axum_extra::extract::cookie - Rust - Docs.rs
This value must be returned from the handler as part of the response for the changes to be propagated. Example. use axum::{ Router,...
Read more >Using cookies - Postman Learning Center
To retrieve a cookie, use the .get() function. This function takes a URL and the name of the required cookie. It returns the...
Read more >CookieJar object - Grafana k6
CookieJar ; cookiesForURL(url), Get Object of cookies where the key is the cookie name and the value is an array. ; set(url, name,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Cookie.parse
parses cookie string like the one you set in browser fordocument.cookie
. Meanwhile,jar.getCookiesSync
returns array of data structures that represent already parsed cookie. Thus, to accessvalue
of the particular cookie you need to scan returned array for requiredkey
and use it’svalue
property. If you need to get string representation of the current cookie jar like the one that returned by browser inCookies
header, then you can usejar.getCookieString
method. This interactive example shows both approaches: https://runkit.com/580f9ad527cf550013c20537/58cc1078e26e580014605e9eHello Everyone, I have few cookies stored with domain .xxxx.local. when i did `const jar = new CookieJar(); const cookies = jar.getCookiesSync(‘http://xxxx.local’);
I got empty arrays. what is the way to get the cookies.