Last active
August 14, 2022 13:38
-
-
Save artturik/a15d890dcfedfe8af813 to your computer and use it in GitHub Desktop.
Convert PhantomJs cookies to NetScape HTTP cookie file format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
}; |
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
Nice!