can phantomjs work with node.js?

前端 未结 7 1700
难免孤独
难免孤独 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:26

    You could also give phridge a try. Your example would've been written like this:

    var phantom;
    
    // spawn a new PhantomJS process
    phridge.spawn()
        .then(function (ph) {
            phantom = ph;
            return phantom.openPage("http://www.google.com");
        })
        .then(function (page) {
            return page.run(function () {
                // this function runs inside PhantomJS with this bound to a webpage instance
                return this.title;
            });
        })
        .then(function (title) {
            console.log('Page title is ' + title);
            // terminates the process cleanly
            phantom.dispose();
        });
    

提交回复
热议问题