1.下載phantomjs.exe 下載地址:
https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-windows.zip
http://zhouhua.qiniudn.com/work/nodejs/phantomjs.zip
2.安裝phantomjs.exe, 對這個這執行性文件 設置環境變量如圖
3.創建一個test.js文件
var page = require('webpage').create(),
system = require('system'),
t,address; //獲取保存名稱和要生成的網址
if (system.args.length === 1) {
console.log('url loss');
phantom.exit();
} else {
t = Date.now();
address = system.args[1];
page.open(address, function(success){
if(success==='success'){
console.log('success');
page.render('D:/'+t+'.png'); //圖片保存路徑 @可寫權限
phantom.exit();
}else{
console.log('error');
phantom.exit();
}
});
}
//eq: http://localhost/cwb.php?url=http://www.ktuo.cn
$url = $_GET['url'];
exec("phantomjs D:/dapeng/test.js ".$url,$out); //運行js文件
print_r($out);