简体   繁体   English

Windows上的Phantomjs

[英]Phantomjs on windows

i have the following very simple code: 我有以下非常简单的代码:

 var phantom = require('phantomjs');
phantom.create(function(ph){
                ph.createPage(function(page) {
                    page.open("http://www.google.com", function(status) {
                        page.render('google.pdf', function(){
                            console.log('Page Rendered');
                            ph.exit();
                        });
                    });
                });
            });

When i run this i get an undefined is not a function error at the line phantom.create() 当我运行它时,我在phantom.create()行上得到undefined is not a function错误

I am right now sitting on a windows machine and read somewhere that i might have to use something called dnode my question is could this be the cause of the error or is there something in the code that might be wrong? 我现在正坐在Windows机器上,阅读某处可能需要使用dnode我的问题是这是导致错误的原因,还是代码中可能存在错误?

Update 更新

I've changed var phantom = requiere(phantomjs) to be var phantom = requiere(phantom) , but now i get the error: 我已经将var phantom = requiere(phantomjs)更改为var phantom = requiere(phantom) ,但是现在我得到了错误:

phantom stderr: 'phantomjs' is not recognised as an internal or external kommand, a program or a batchfil.
...    
AssertionError: abnormal phantomjs exit code: 1

You're getting mixed up between phantomjs and phantom node.js modules. 您在phantomjsphantom node.js模块之间phantomjs

Your code follows the phantom module's pattern it looks like: https://www.npmjs.com/package/phantom (this is a node wrapper for phantomjs) 您的代码遵循phantom模块的模式,如下所示: https ://www.npmjs.com/package/phantom(这是phantomjs的节点包装器)

So, require phantom, instead of phantomjs 因此,需要phantom,而不是phantomjs

Be sure to have run npm install phantom before this 确保在此之前运行npm install phantom

var phantom = require('phantom'); //not phantomjs
phantom.create(function(ph){
                ph.createPage(function(page) {
                    page.open("http://www.google.com", function(status) {
                        page.render('google.pdf', function(){
                            console.log('Page Rendered');
                            ph.exit();
                        });
                    });
                });
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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