FunnyWeb

据说这里有很多神奇的东西...

CentOS6.4使用phantomjs抓取网页截图

2016-05-15 14:42:252066 views

使用phantomjs抓取网页截图

安装phantomjs

wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-i686.tar.bz2 
tar jxvf phantomjs-2.1.1-linux-i686.tar.bz2
mv phantomjs-2.1.1-linux-i686 phantomjs

(修改文件夹名字 可以不改)

测试命令

./bin/phantomjs examples/netsniff.js http://www.baidu.com

报错

./bin/phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory

安装fontconfig

yum -y install fontconfig

测试命令

./bin/phantomjs examples/netsniff.js http://www.baidu.com

执行成功

./bin/phantomjs examples/hello.js

网页截图js

vi examples/savepic.js
var page = require('webpage').create();
page.open('http://www.baidu.com', function() {
  page.render('example.png');
  phantom.exit();
});
./bin/phantomjs examples/savepic.js

发现中文未显示,需要安装中文字体库

yum install bitmap-fonts bitmap-fonts-cjk

安装后测试正常...