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

what's the difference difference between phantom.exit and .close in phantom.js?

如果我正在使用 phantom.js 进行网络抓取以单击一些按钮和链接,使用什么来终止程序最方便?

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

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

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

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

var webPage = require('webpage');
var page = webPage.create();

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

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

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

如果您执行大量自动化任务,打开页面而不是关闭它们 - 这可能会导致内存泄漏。

因此,首选的终止方式是 1. 关闭页面,然后 2. 退出 phantom。