After running this code he save an infinite number of files with the source code of the first page(\"http://site1.com\"), why he doesn\'t go through other links and doesn\'t sto
page.evaluate()
is the sandboxed page context in PhantomJS. It doesn't have access to any variable defined outside. So you cannot reference fs
or page
inside of it and you don't need to, because page.content
is available in the outer context:
page.open(file,function(){
fs.write(i + '.html', page.content, 'w');
setTimeout(next_page,100);
});
The remaining code looks fine.