参考:html
https://www.cnblogs.com/10-22/articles/4383196.htmllinux
http://www.javashuo.com/article/p-xssbbamn-du.htmlweb
https://www.jianshu.com/p/fd76e68ce59b缓存
1.下载测试
官网:https://phantomjs.org/download.html字体
2.安装依赖ui
yum install -y bzip2 # 安装bzip2 yum install -y fontconfig freetype2 yum install bitmap-fonts bitmap-fonts-cjk yum groupinstall "fonts" -y # 安装字体相关的依赖包 fc-cache # 刷新字体缓存
3.安装lua
tar -jxvf phantomjs-2.1.1-linux-x86\_64.tar.bz2 mv phantomjs-2.1.1-linux-x86\_64 /usr/local/src/phantomjs ln -sf /usr/local/src/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
4.调试调试
查看版本code
phantomjs -v # 测试版本号
测试脚本test.js (返回指定网页内第一个div的内容)
var page = require('webpage').create(), system = require('system'), address; address = system.args\[1\]; page.open(address, function (status) { if (status !== 'success') { console.log('Unable to access network'); } else { var ua = page.evaluate(function () { return document.getElementsByTagName('div')\[0\].textContent; }); console.log(ua); } phantom.exit(); });
执行脚本
phantomjs test.js http://xxx.com/test.html
5.在PHP中调用
exec("phantomjs /script/test.js http://xxx.com/test.html");