gpt4 book ai didi

javascript - Windows 上的 Phantomjs

转载 作者:行者123 更新时间:2023-11-30 16:50:22 25 4
gpt4 key购买 nike

我有以下非常简单的代码:

 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 模块。

您的代码遵循 phantom 模块的模式,如下所示:https://www.npmjs.com/package/phantom(这是 phantomjs 的 Node 包装器)

所以,需要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();
});
});
});
});

关于javascript - Windows 上的 Phantomjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30624265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com