PhantomJS 安装

PhantomJS 安装

图片描述

Mac OS X && Windows

一、PhantomJS下载地址html

按照系统下载对应的版本,

macOS 下载: phantomjs-2.1.1-macosx.zip

Windows下载:phantomjs-2.1.1-windows.zip

并解压到用户目录下面,

macOS 解压路径:

/User/xxx/phantomjs-2.1.1-macosx

Windows 解压路径:

D:\phantomjs-2.1.1-windows ,并重命名为 D:\phantomjs

二、PhantomJS不须要安装,解压便可使用node

Windows PATH变量

在“系统变量”选项区域中查看PATH变量,若是不存在,则新建变量 PATH,

不然选中该变量,单击“编辑”按钮,在“变量值”文本框的起始位置添加 

D:\phantomjs\bin,开始-运行-输入cmd,输入 phantomjs --version, 
 
若是能够看到版本号,则安装成功。

macOS PATH变量

若是用户目录下存在 .bash_profile ,好比个人/User/xxx/.bash_profile,则添加一行 

export PATH="$PATH:/Users/xxx/phantomjs-2.1.1-macosx/bin"

不然新建 .bash_profile,而后在添加上文

在terminal中输入

phantomjs --version

若是能够看到版本号,则安装成功。

三、使用npm安装的时候如何环境变量中没有phantomjs,就会从github下载安装phantomjs,可是你懂的?,大多数状况下会超时,即便把npm的镜像改为淘宝的仍是同样的结果git

PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-macosx.zip
Saving to /var/folders/hn/55rkvgy97797tgx6cld83zl80000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip
  • 而后聪明的你想到可使用 npm install -g phantomjs , 但是现实告诉你github

npm WARN deprecated phantomjs@2.1.7: Package renamed to phantomjs-prebuilt. Please update 'phantomjs' package references to 'phantomjs-prebuilt'
npm WARN deprecated tough-cookie@2.2.2: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
/usr/local/bin/phantomjs -> /usr/local/lib/node_modules/phantomjs/bin/phantomjs

> phantomjs@2.1.7 install /usr/local/lib/node_modules/phantomjs
> node install.js

Considering PhantomJS found at /usr/local/bin/phantomjs
Looks like an `npm install -g`
Error checking path, continuing { Error: Cannot find module '/usr/local/lib/node_modules/phantomjs/lib/location'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at getLocationInLibModuleIfMatching (/usr/local/lib/node_modules/phantomjs/install.js:332:19)
    at Promise._successFn (/usr/local/lib/node_modules/phantomjs/install.js:389:28)
    at nextTickCallback (/usr/local/lib/node_modules/phantomjs/node_modules/kew/kew.js:47:28)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9) code: 'MODULE_NOT_FOUND' }
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1//phantomjs-2.1.1-macosx.zip
Saving to /usr/local/lib/node_modules/phantomjs/phantomjs/phantomjs-2.1.1-macosx.zip
Receiving...
  • 又回到了原点,是否是npm的问题?我用cnpm试一下看看macos

  • 而后聪明的你想到可使用 cnpm install -g phantomjs,现实是这样npm

Downloading phantomjs to /usr/local/lib/node_modules/phantomjs_tmp
Copying /usr/local/lib/node_modules/phantomjs_tmp/.2.1.7@phantomjs to /usr/local/lib/node_modules/phantomjs
Installing phantomjs's dependencies to /usr/local/lib/node_modules/phantomjs/node_modules
[1/8] progress@~1.1.8 installed at node_modules/.1.1.8@progress
...
[8/8] request@~2.67.0 installed at node_modules/.2.67.0@request
execute post install 1 scripts...
[1/1] scripts.install phantomjs@2.1.7+deprecated run "node install.js"
PhantomJS not found on PATH
Phantom installation failed TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.join (path.js:1211:7)
Install fail! Error: post install error, please remove node_modules before retry!
Run "sh -c node install.js" error, exit code 1
Error: post install error, please remove node_modules before retry!
Run "sh -c node install.js" error, exit code 1
    at ChildProcess.proc.on.code (/usr/local/lib/node_modules/cnpm/
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
npminstall version: 2.26.2
npminstall args: /usr/local/bin/node /usr/local/lib/node_modules/cnpm/node_modules/npminstall/bin/install.js --china --userconfig=/Users/azmake/.cnpmrc --disturl=https://npm.taobao.org/mirrors/node --registry=https://registry.npm.taobao.org -g phantomjs
  • 看到提示windows

Install fail! Error: post install error, please remove node_modules before retry!
  • 什么鬼?不陪你玩了bash

sudo npm uninstall -g phantomjs

sudo cnpm uninstall -g phantomjs

sudo rm -rf /usr/local/lib/node_modules/phantomjs
  • 而后你又想到可使用HomeBrew安装cookie

brew install phantomjs
  • ok,安装完成,打开terminal,输入 phantomjs --version,能够看到版本号,一块儿正常,能够愉快的玩耍了,而后你又愉快的开始 npm install 了,而后你又发现 使用phantomjs的项目里面 could not verify phantomjs,而后ide

Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1//phantomjs-2.1.1-macosx.zip
Saving to /usr/local/lib/node_modules/phantomjs/phantomjs/phantomjs-2.1.1-macosx.zip
Receiving...

总结

一、可使用cnpm install 安装使用phantomjs的项目的node_modules,cnpm 会 使用phantomjs-prebuilt代替phantomjs,而且不中途翻车

二、下载安装phantomjs,并配置环境变量,这样无论是cnpm install仍是npm install均可以使用phantomjs,并且在pycharm里面也不会报找不到phantomjs的错误

相关文章
相关标签/搜索