Skip to content

Instantly share code, notes, and snippets.

@artturik
Last active August 14, 2022 13:38
Show Gist options
  • Save artturik/a15d890dcfedfe8af813 to your computer and use it in GitHub Desktop.
Save artturik/a15d890dcfedfe8af813 to your computer and use it in GitHub Desktop.
Convert PhantomJs cookies to NetScape HTTP cookie file format
// Convert PhantomJs cookies to NetScape HTTP cookie file format
// NOTE: It dose not create NetScape HTTP cookie file, this function return only cookie file contents
// NOTE: PhantomJs do not store "host only" cookie param, all cookies will have "host only" param set to false (line 15)
// I use this function to export PhantomJs cookies to CURL cookiejar file
// This is modified version of EditThisCookie cookie_helpers.js cookiesToString function
// USAGE: phantomJsCookiesToNetScapeString(phantom.cookies);
var phantomJsCookiesToNetScapeString = function(cookies) {
var string = "";
string += "# Netscape HTTP Cookie File\n";
string += "# http://curl.haxx.se/rfc/cookie_spec.html\n";
for(var i=0; i<cookies.length; i++) {
cookie = cookies[i];
string += cookie.domain + "\t" +
'FALSE' + "\t" +
cookie.path + "\t" +
cookie.secure.toString().toUpperCase() + "\t" +
((cookie.expiry != undefined) ? cookie.expiry : "") + "\t" +
cookie.name + "\t" +
cookie.value + ((i==cookies.length-1) ? "" : "\n");
}
return string;
};
@thoughtchad
Copy link

Nice!

@leopucci-zz
Copy link

Thanks! Just what i was looking for!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment