phantomjs 保存網頁快照

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();
	}
});
}


4.創建已個php運行文件


  //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);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章