參考: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");