簡體   English   中英

Windows上的Phantomjs

[英]Phantomjs on windows

我有以下非常簡單的代碼:

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

當我運行它時,我在phantom.create()行上得到undefined is not a function錯誤

我現在正坐在Windows機器上,閱讀某處可能需要使用dnode我的問題是這是導致錯誤的原因,還是代碼中可能存在錯誤?

更新

我已經將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

您在phantomjsphantom node.js模塊之間phantomjs

您的代碼遵循phantom模塊的模式,如下所示: https ://www.npmjs.com/package/phantom(這是phantomjs的節點包裝器)

因此,需要phantom,而不是phantomjs

確保在此之前運行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