Ubuntu下phantomjs的安装

1、安装

ubuntu下面可以直接使用命令安装(不可用)

sudo apt-get install phantomjs

 官方下载:

# 官方网站:
http://phantomjs.org/download.html 
# 淘宝镜像:
https://npm.taobao.org/mirrors/phantomjs 

 2、解压

tar -xvf phantomjs-1.9.7-linux-i686.tar.bz2
# 注:解压失败,出现一下错误时,先查看压缩包是什么类型 file phantomjs-1.9.7-linux-i686.tar.bz2 看是否是bzip2类型再解压
# bzip2: (stdin) is not a bzip2 file.
# tar: Child returned status 2
# tar: Error is not recoverable: exiting now

3、创建软链接到环境变量中。这样可以直接在shell中使用phantomjs命令:

sudo ln -sf /usr/local/src/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
# 其中的参数s表示为软链接,参数f表示强制。
#(或)添加到系统常量:
cp phantomjs /usr/local/bin

4、查看是否安装成功:

 

phantomjs –v

 

出现版本号则为成功安装

 

 

 注意:

phantomjs中截图无法生成原因是 phantomjs执行需要root权限

sudo phantomjs hello.js

 phantomjs无法获取https网址的内容原因是因为ssl不安全,需设置

phantomjs --ignore-ssl-errors=true --ssl-protocol=any loadspeed.js https://www.baidu.com 
原文地址:https://www.cnblogs.com/yekushi-Z/p/10874135.html