IT源码网

phantomjs的使用

sanshao 2021年02月16日 编程语言 419 0
var page = require('webpage').create(); 
page.open('http://example.com', function(status) { 
  console.log("Status: " + status); 
  if(status === "success") { 
    page.render('example.png'); 
  } 
  phantom.exit(); 
}); 
 
网页截图
var page = require('webpage').create(), 
  system = require('system'), 
  t, address; 
 
if (system.args.length === 1) { 
  console.log('Usage: loadspeed.js <some URL>'); 
  phantom.exit(); 
} 
 
t = Date.now(); 
address = system.args[1]; 
page.open(address, function(status) { 
  if (status !== 'success') { 
    console.log('FAIL to load the address'); 
  } else { 
    t = Date.now() - t; 
    console.log('Loading ' + system.args[1]); 
    console.log('Loading time ' + t + ' msec'); 
  } 
  phantom.exit(); 
}); 
 
phantomjs loadspeed.js http://www.google.com 
 
网站测速

更多例子

http://phantomjs.org/examples/index.html

评论关闭
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

python的pip安装