惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
J
Java Code Geeks
量子位
腾讯CDC
C
Check Point Blog
小众软件
小众软件
IT之家
IT之家
I
InfoQ
Hugging Face - Blog
Hugging Face - Blog
Stack Overflow Blog
Stack Overflow Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
GbyAI
GbyAI
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
博客园_首页
S
SegmentFault 最新的问题
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
Martin Fowler
Martin Fowler

博客园 - 卡卡西村长

QT使用linuxdeployqt打包 统计vertica表的行数 基于QScintilla项目实现SQL编辑器 Vertica中的group_concat函数 查看mysql当前事务锁并kill vscode中文乱码问题及几种常见的解决方案 改善[Vertica] current ResultSet because its buffer(8192) is full的错误 通过 phantomjs抓取仁医在线的练习题 notepad++ 配置fasm汇编环境 springboot动态启用RabbitMQ消费Listener mysql日期字段分区索引 排查tomcat服务器CPU占用率过高的问题 FFMPEG把图片序列合成为视频 统计nginx日志中的ipv4和ipv6占比 vertica性能优化汇总 oracle unwrap解密工具 windows10上安装OpenSSL_1.1.1d_x64 如何用Java Socket实现一个简单的Redis客户端 cenos上通过yum安装mariadb
centos7上安装phantomjs并对页面截屏
卡卡西村长 · 2021-05-27 · via 博客园 - 卡卡西村长

安装
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
yum install bzip2
tar -jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2
mv phantomjs-2.1.1-linux-x86_64 /usr/local/src/phantomjs
ln -sf /usr/local/src/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
yum install -y fontconfig freetype2
yum install -y bitmap-fonts bitmap-fonts-cjk
yum groupinstall "fonts" -y
fc-cache
phantomjs -v

测试1

创建一个文件:hello.js

console.log('Hello, world!');
phantom.exit();

运行:phantomjs hello.js

输出:Hello, world!

测试2

创建一个文件:example.js

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

运行:phantomjs example.js

输出图片文件:./example.png

测试3

默认的截图尺寸是400*300,这个太小了,可以指定浏览器可视区域尺寸。

var page = require('webpage').create();
var w = 1920;
var h = 792;
page.viewportSize = { width: w, height: h };
page.clipRect = { top: 0, left: 0, width: w, height: h };
page.open('http://example.com/', function(status) {
  console.log("Status: " + status);
  if(status === "success") {
    page.render('./example.png');
  }
  phantom.exit();
});

测试4

对于异步加载的页面,需要等会待会才能截图。

var page = require('webpage').create();
var w = 1920;
var h = 792;
page.viewportSize = { width: w, height: h };
page.clipRect = { top: 0, left: 0, width: w, height: h };
page.open('http://example.com', function() {
  console.log("Status: " + status);
  if(status === "success") {
    window.setTimeout(function () {
        page.render('./example.png');
        phantom.exit();
    }, 3000);
  } else {
    console.log('Unable to load the address!');
    phantom.exit(1);
  }
});