当前位置: 首页 > news >正文

PhantomJS 安装

PhantomJS 安装

图片描述

Mac OS X && Windows

1、PhantomJS下载地址

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

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

2、PhantomJS不需要安装,解压即可使用

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

如果可以看到版本号,则安装成功。

3、使用npm安装的时候如何环境变量中没有phantomjs,就会从github下载安装phantomjs,但是你懂的?,大多数情况下会超时,即使把npm的镜像改成淘宝的还是一样的结果

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 , 可是现实告诉你

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试一下看看

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

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
  • 看到提示

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

sudo npm uninstall -g phantomjs

sudo cnpm uninstall -g phantomjs

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

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

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...

总结

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

2、下载安装phantomjs,并配置环境变量,这样不管是cnpm install还是npm install都可以使用phantomjs,而且在pycharm里面也不会报找不到phantomjs的错误

相关文章:

  • 翻转式用户登录注册界面设计
  • Web应用防护系统OpenWAF开源CC防护模块
  • python运算符优先级
  • 设计模式C++实现——模板方法模式
  • 第四(装饰器、迭代器、生成器)
  • windows下实现快捷键截图小工具
  • 【jQuery】学习jQuery插件的使用与写法(表单验证插件-validation)
  • Oracle使用row_number()函数查询时增加序号列
  • 【Java基础】序列化与反序列化深入分析
  • Elasticsearch前沿:ES 5.x改进详解与ES6展望
  • 一次因为文件名开头包含空格而导致FTP文件一直无法下载的悲剧!
  • node-glob通配符
  • Bzoj1005 [HNOI2008]明明的烦恼
  • 正则表达式 取反 非
  • Git学习与使用心得(1)—— 初始化
  • [LeetCode] Wiggle Sort
  • ES10 特性的完整指南
  • ES6系列(二)变量的解构赋值
  • FastReport在线报表设计器工作原理
  • Java到底能干嘛?
  • js如何打印object对象
  • JWT究竟是什么呢?
  • MySQL QA
  • PAT A1092
  • Promise初体验
  • Redis 中的布隆过滤器
  • Synchronized 关键字使用、底层原理、JDK1.6 之后的底层优化以及 和ReenTrantLock 的对比...
  • WinRAR存在严重的安全漏洞影响5亿用户
  • 半理解系列--Promise的进化史
  • 二维平面内的碰撞检测【一】
  • 关于 Cirru Editor 存储格式
  • 关于字符编码你应该知道的事情
  • 每天10道Java面试题,跟我走,offer有!
  • 普通函数和构造函数的区别
  • 如何实现 font-size 的响应式
  • 微信小程序开发问题汇总
  • 问题之ssh中Host key verification failed的解决
  • 大数据全解:定义、价值及挑战
  • ​DB-Engines 12月数据库排名: PostgreSQL有望获得「2020年度数据库」荣誉?
  • ​人工智能书单(数学基础篇)
  • #NOIP 2014# day.1 T2 联合权值
  • (33)STM32——485实验笔记
  • (C语言)深入理解指针2之野指针与传值与传址与assert断言
  • (iPhone/iPad开发)在UIWebView中自定义菜单栏
  • (SpringBoot)第七章:SpringBoot日志文件
  • (博弈 sg入门)kiki's game -- hdu -- 2147
  • (二)Eureka服务搭建,服务注册,服务发现
  • (附源码)springboot助农电商系统 毕业设计 081919
  • (七)微服务分布式云架构spring cloud - common-service 项目构建过程
  • (转)关于pipe()的详细解析
  • ***原理与防范
  • ... 是什么 ?... 有什么用处?
  • .Net 高效开发之不可错过的实用工具
  • .NET 解决重复提交问题
  • .NET/C# 项目如何优雅地设置条件编译符号?