1.创建pageload.js文件:

pageload.js

 1 var page = require('webpage').create();
 2 var address = 'https://www.baidu.com/';//填写需要打印的文件位置
 3 var output = './img/'+'baidu'+'.png';//存储文件路径和名称
 4 page.viewportSize = { width: 100, height: 100 };//设置长宽
 5 page.open(address, function (status) {
 6     if (status !== 'success') {
 7         console.log('Unable to load the address!');
 8         phantom.exit();
 9     } else {
10         window.setTimeout(function () {
11             page.render(output);
12             phantom.exit();
13         }, 500);
14     }
15 });

 

2.测试,先通过命令行进入到该文件的目录:

phantomjs学习之截图

phantomjs pageload.js

 

3.运行成功后会生成图片,如:

phantomjs学习之截图

 

相关文章:

  • 2021-09-10
  • 2021-09-13
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2022-03-03
  • 2022-12-23
猜你喜欢
  • 2021-12-10
  • 2021-09-18
  • 2021-05-16
  • 2021-05-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案