• Web前端学习笔记之安装和使用PhantomJS


    0x00 安装PhantomJS(linux环境安装)

    将PhantomJS下载在/usr/local/src/packet/目录下(这个看个人喜好)

    操作系统:CentOS 7 64-bit

    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/

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

    [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]#

    0x01 安装PhantomJS(windows环境安装)

    1.下载的文件名:phantomjs-2.1.1-windows.zip,直接解压出来,解压后的文件复制到你电脑的任意盘(我是放在D盘),建议别放c盘,然后进入解压目录,phantomjs-2.1.1in下有个phantomjs.exe,双击就可以进入命令行了;

     2.添加环境变量,在cmd中就可使用phantomjs命令了,添加完之后就是以下界面:

    OK,部署完成

    0x02 使用PhantomJS

    网址1:http://javascript.ruanyifeng.com/tool/phantomjs.html 

    网址2(官网):http://phantomjs.org/api/webpage/

  • 相关阅读:
    开始学习C#
    关于串口数据读取的几个问题
    Joel测试
    VC查找内存泄漏技巧【转】
    思考题一
    自我介绍
    2020面向对象程序设计寒假作业1 题解
    思考题二
    题解 洛谷P2158 【[SDOI2008]仪仗队】
    深入浅出InfoPath系列
  • 原文地址:https://www.cnblogs.com/JetpropelledSnake/p/9893550.html
Copyright © 2020-2023  润新知