Centos7 安装PhantomJS

1.下载地址:http://phantomjs.org/download.html

2.文件名:phantomjs-2.1.1-linux-x86_64.tar.bz2

 
# 下载好后进行解压(由于是bz2格式,要先进行bzip2解压成tar格式,再使用tar解压)
bzip2 -d phantomjs-2.1.1-linux-x86_64.tar.bz2

# 再使用tar进行解压到/usr/local/目录下边
tar xvf phantomjs-2.1.1-linux-x86_64.tar -C /usr/local/ # 安装依赖软件 yum -y install wget fontconfig # 重命名(方便以后使用phantomjs命令) mv /usr/local/phantomjs-2.1.1-linux-x86_64/ /usr/local/phantomjs # 最后一步就是建立软连接了(在/usr/bin/目录下生产一个phantomjs的软连接,/usr/bin/是啥目录应该清楚,不清楚使用 echo $PATH查看) ln -s /usr/local/phantomjs/bin/phantomjs /usr/bin/ 

或者

wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-i686.tar.bz2
tar jxvf phantomjs-1.9.8-linux-i686.tar.bz2
mv phantomjs-1.9.8-linux-i686 /usr/local/src/phantomjs
ln -sf /usr/local/src/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
复制代码

到这一步就安装成功了,接下来测试一下(经过上面建立的软连接,你就可以使用了,而且是想使用命令一样的进行使用哦!):

[root@localhost ~]# phantomjs 
phantomjs> 

接下来咱们建立一个文件来测试一下:

复制代码
# 建立一个新文件 并写入 console.log('Hello world!) phantom.exit();
[root@localhost roottest]# vim test.js

# 查看一下
[root@localhost roottest]# cat test.js 
console.log('Hello world!'); phantom.exit();//这一行表示退出命令行 # 执行一下试试(OK了) [root@localhost roottest]# phantomjs test.js Hello world!
复制代码

至于很多人可能很疑惑,进入命令行后怎么退出命令行,目前本人知道的就是按 Ctrl + c 组合键退出和 phantom.exit();退出命令行了

复制代码
[root@localhost roottest]# phantomjs 
phantomjs> exit();
Can't find variable: exit

  phantomjs://repl-input:1 in global code phantomjs> phantom.exit(); [root@localhost roottest]# 

猜你喜欢

转载自www.cnblogs.com/sundahua/p/9630809.html