简体   繁体   中英

Node.js and phantom issue

I'm playing around with Node.js and the node phantom module that is available. But I seem to be stuck at a basic level, and can't get this basic piece of code to work:

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

I can't really figure out why the console messages don't appear? This happen to be in some phantom scope, I guess, but would it be possible for me to have the messages be parsed on to node? Or is the problem something completely else?

From the readme:

First, make sure PhantomJS is installed. This module expects the phantomjs binary to be in PATH somewhere. In other words, type this:

$ phantomjs

If that works, so will phantomjs-node. It's only been tested with PhantomJS 1.3, and almost certainly doesn't work with anything older.

if that doesnt work (what i expect) install phantomjs: http://phantomjs.org/download.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM