问题描述
我正在尝试使用PhantomJS,并且已经通过NPM安装了它.我似乎无法运行任何一个示例,实际上我什至无法运行:
I'm attempting to use PhantomJS, and I've installed it via NPM.I can't seem to run any of the of the examples, in fact I can't even run:
var page = require('webpage').create();
我得到了错误:
Error: Cannot find module 'webpage'
我有什么想念的吗?我正在使用通过NPM在同一目录中安装的其他一些模块,没有任何问题
Is there anything i'm missing? I'm using a few other modules that I've installed via NPM in the same directory with no issues
推荐答案
对于Node.js,PhantomJS 不是.您可能通过node
二进制文件来运行示例.
PhantomJS is not for Node.js. You are likely running the examples through node
binary.
仔细阅读入门文档,您会发现每个PhantomJS示例都需要调用方式如下:
Read the Getting Started documentation carefully and you'll see that every single PhantomJS example need to be invoked like:
phantomjs hello.js
请注意,Node.js和PhantomJS之间有一个 bridge .在这种情况下,您需要遵循特定桥梁的给定示例(有一些不同的示例).
Note that there is a bridge between Node.js and PhantomJS. In that case, you need to follow the given examples for that particular bridge (there are a few different ones).
这篇关于在node.js中直接使用PhantomJS的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!