You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

var system = require('system');
var page = require('webpage').create();
// 如果是windows,设置编码为gbk防止中文乱码,Linux本身是UTF-8
var osName = system.os.name;
console.log('os name:' + osName);
if ('windows' === osName.toLowerCase()) {
phantom.outputEncoding="gbk";
}
// 获取第二个参数(即请求地址url).
var url = system.args[1];
console.log('url:' + url);
// 显示控制台日志.
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
//打开给定url的页面.
var start = new Date().getTime();
page.open(url, function(status) {
if (status == 'success') {
console.log('echarts页面加载完成,加载耗时:' + (new Date().getTime() - start) + ' ms');
// 由于echarts动画效果延迟200毫秒确保图片渲染完毕再调用下载图片方法.
setTimeout(function() {
//参考文档https://gitee.com/hbun_gao/echartsconvert-master
page.evaluate(function() {
postImage();
console.log("调用了echarts的下载图片功能.");
});
}, 200);
} else {
console.log("页面加载失败 Page failed to load!");
}
// 1秒后再关闭浏览器.
setTimeout(function() {
phantom.exit();
}, 1000);
});