Node.js控制远程PhantomJS实例的简便包装器node-phantomjs-wrapper

简介

node-phantomjs-wrapper 提供了一个简易的API包装器来控制PhantomJS的远程实例,并简化了从 Node.jsPhantomJS 的控制。虽然该项目已停止维护,但其便捷的功能仍为一些开发者提供了实用的接口。

安装

npm install phantomjs-wrapper

用法

node-phantomjs-wrapperPhantomJS 二进制文件提供了一个简单的包装器,能通过 stdioPhantomJS 内置的Web服务器,以 JSON协议 转发消息到子 PhantomJS 进程并接收返回消息。

示例

以下是一个可以直接在 Node.js REPL 中运行的简单示例:

const phantomjsWrapper = require('phantomjs-wrapper');
phantomjsWrapper({ timeout: 60000 }, function(err, phantomjs) {
  if (err) {
    console.error('Error:', err);
  } else {
    console.log('PhantomJS instance created successfully');
    // 在这里可以添加更多PhantomJS控制逻辑
  }
});

支持的事件与方法

该包装器提供了诸如 打开页面执行脚本 等一系列方法和事件,能够满足基本的 PhantomJS 自动化需求。

zip 文件大小:8.19KB