As a new user to PhantomJS I want to be sure that I understand how PhantomJS handles any persistence of data that it accumulates from a HTTP request.
My question is: Does PhantomJS store any data persistently by default (i.e. a simple example where you are not using require('fs')
anywhere in the script to store the request, just dumping it out to STDOUT
). I am assuming that all of the work from a page.evaluate()
call is done in memory.
Here is a simple example for illustration:
var page = require('webpage').create(),
system = require('system'),
address;
if(system.args.length != 2)
{
console.log('Usage: phantomjs thisFile.js URL');
phantom.exit(1);
}
else
{
address = system.args[1];
page.open(address, function (status)
{
if(status !== 'success')
{
console.log('Unable to load the address!');
phantom.exit(1);
}
else
{
// Wait for the js to finish loading
window.setTimeout(function(){
var results = page.evaluate(function(){
return document.documentElement.innerHTML;
});
console.log(results); // This would be to stdout
phantom.exit(0);
}, 200);
}
console.log("Done.");
});
}
This script would be called by something like phantomjs thisScript.js www.example.com
.
I know that you can save a page to file, I just want to be sure that I am aware of all the places that PhantomJS may accumulate data on its own.
I also have looked into how PhantomJS handles cookies.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…