简体   繁体   English

PhantomJs安装

[英]PhantomJs installation

I'm new with phantomJS , I'v installed it and saved the file in this path C:\\bin\\Phantomjs\\phantomjs-1.9.7-windows and added this to the windows PATH. 我是phantomJS的新手,我已经安装它并将文件保存在此路径C:\\ bin \\ Phantomjs \\ phantomjs-1.9.7-windows中,并将其添加到Windows PATH中。 in their manual it says to create a JS file and write the following and save it as hello.js: 在他们的手册中说创建一个JS文件并编写以下内容并将其另存为hello.js:

console.log('Hello, world!'); console.log('Hello,world!'); phantom.exit(); phantom.exit();

then open the command line and type : phantomjs hello.js 然后打开命令行并输入:phantomjs hello.js

I keep getting an error that says "parse error". 我不断收到一个错误,提示“解析错误”。

and when entering the file phantomjs and it becomes "phantomjs> " and i write hello.js i get another error " cannot find variable : hello " 当输入文件phantomjs时,它变成“ phantomjs>”,我写了hello.js,我收到另一个错误“找不到变量:hello”

How can i access the hello file ? 如何访问hello文件?

thanks 谢谢

The basic scenario would be to place your JS file in the same folder as phantomjs.exe 基本方案是将JS文件与phantomjs.exe放在同一文件夹中

  1. Navigate to the folder with phantomjs.exe and your js file 使用phantomjs.exe和您的js文件导航到该文件夹
  2. Press CTRL + Shift + Mouse Right click and select 'Open command window here' CTRL + Shift + 鼠标右键单击并选择“在此处打开命令窗口”
  3. Enter: phantomjs <fileName>.js 输入: phantomjs <fileName>.js

If this works you can expand the example from there with your path vars. 如果可行,您可以使用路径变量从那里展开示例。 Run this example to make sure that everything is set up correctly 运行此示例以确保所有设置均正确

Also when you just type phantomjs, you are entering its console where you can execute javascript code. 同样,当您只键入phantomjs时,您将进入其控制台,您可以在其中执行javascript代码。 So when you type in hello.js there, it's trying to interpret it as a javascript code and hello is not defined. 因此,当您在此处输入hello.js时,它将尝试将其解释为javascript代码,并且未定义hello。

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

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