免責聲明

Disclaimer (免責聲明)
繼續閱覽代表您接受以上的免責聲明.
To continue reading means you accept the above disclaimer.

2015年6月10日 星期三

nodejs and phantomjs


//=== phantomjs-node module for nodejs
https://github.com/sgentle/phantomjs-node
"""...
This module expects the phantomjs binary to be in PATH somewhere. In other words, type this:

$ phantomjs
If that works, so will phantomjs-node.

..."""

0. verfiy that phantomjs binary already works by
$ phantomjs --version

1. then install phantomjs-node module for nodejs by
$ npm install phantom


[ex]
var phantom = require('phantom');

phantom.create(function (ph) {
ph.createPage(function (page) {
page.open("http://www.google.com", function (status) {
console.log("opened google? ", status);
page.evaluate(function () { return document.title; }, function (result) {
console.log('Page title is ' + result);
ph.exit();
});
});
});
});



"""...
... How do you communicate with a process that doesn't support shared memory, sockets, FIFOs, or standard input?

Well, there's one thing PhantomJS does support, and that's opening webpages. In fact, it's really good at opening web pages. So we communicate with PhantomJS by spinning up an instance of ExpressJS, opening Phantom in a subprocess, and pointing it at a special webpage that turns socket.io messages into alert() calls. Those alert() calls are picked up by Phantom and there you go!

The communication itself happens via James Halliday's fantastic dnode library, which fortunately works well enough when combined with browserify to run straight out of PhantomJS's pidgin Javascript environment.

..."""



//=== phantomjs module for nodejs
https://www.npmjs.com/package/phantomjs
[ An NPM wrapper for PhantomJS ]


$ npm install phantomjs

Or grab the source and

$ node ./install.js

What this installer is really doing is just grabbing a particular "blessed" version of PhantomJS

"""...
PhantomJS is not a library for NodeJS. It's a separate environment and code written for node is unlikely to be compatible. In particular PhantomJS does not expose a Common JS package loader.

This is an 'NPM wrapper' and can be used to conveniently make Phantom available.
It is not a 'NodeJS wrapper'.

... drive from within a node program by spawning phantom in a child process.

... tell NPM and the PhantomJS installer to skip validation of ssl keys with NPM's strict-ssl setting:

$ npm set strict-ssl false



..."""


//=== node-phantom module for nodejs
https://www.npmjs.com/package/node-phantom
[ This is a bridge between PhantomJs and Node.js. ]

0. The bridge assumes that the "phantomjs" binary is available in the PATH.

1. The only other dependency is socket.io

*** need to manually install socket.io and node-phantom

[ex]
var phantom=require('node-phantom');
phantom.create(function(err,ph) {
return ph.createPage(function(err,page) {


//=== phantomjs on nodejs-docker
[err] phantomjs: error while loading shared libraries: libjpeg.so.8: cannot open shared object file: No such file or directory


沒有留言:

張貼留言