can phantomjs work with node.js?

前端 未结 7 1699
难免孤独
难免孤独 2020-11-30 03:56

I would like to use phantomjs in my node.js script. there is a phantomjs-node library.. but unfortunately the author used this weird coffee script code to explain what he\'s

7条回答
  •  渐次进展
    2020-11-30 04:27

    change your code to this, and it will be working:

     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();
           });
         });
       });
     });
    

提交回复
热议问题