Declaring functions
Opened this issue · 1 comments
How can i declare a function?
Example:
I use a script on casperjs to make login, then i save the cookies in Netscape format, to use in curl.
casper.then(function() {
console.log(phantomJsCookiesToNetScapeString(JSON.stringify((this.page.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;
};
Hello, what about using the evaluate function?
$casper->evaluate('var myfunction = function () {}')
and then when needed
$casper->evaluate('myfunction()')