phantom.exit和.close在phantom.js中有什么区别?

如果我正在使用phantom.js进行networking抓取点击一些button,并链接什么是方便终止程序?

http://phantomjs.org/api/webpage/method/close.html http://phantomjs.org/api/phantom/method/exit.html

简短的回答: .close()清除内存, .exit()可能不会。

.close()属于phantomjs的网页。
.exit()属于phantomjs进程本身。

如果你做了很多自动化的任务,打开页面而不closures它们,这可能会导致内存泄漏。

所以最好的终止方式是1.closures页面,然后退出幻像。

PhantomJS .exit()phantom Object的核心方法,您可以使用它来退出phantomjs程序实例(如Nodejs process.exit)。 这是终止你的程序的方便方法。

 console.log('Quitting Phantomjs'); phantom.exit(); 

.close()方法是网页模块的一部分,用于closures网页。

 var webPage = require('webpage'); var page = webPage.create(); page.open('http://github.com', function (status) { if (status === "success") { // do stuff page.close(); } })