Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save plonknimbuzz/c9ded3d2446c4b330a6252ee17a8e8ea to your computer and use it in GitHub Desktop.
Save plonknimbuzz/c9ded3d2446c4b330a6252ee17a8e8ea 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;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment