justcode.ikeepstudying.com
Linux: shell脚本获取网页快照(网页截图)并生成缩略图 - Just Code
获取网页快照并生成缩略图可分两步进行: 1、获取网页快照 2、生成缩略图 获取网页快照 这里我们用 phantomjs 来实现。关于 phantomjs 的详细用法可参考官方网站。 1、安装 我的环境是CentOS6.5,安装时直接下载 tarball 然后解压即可。 最新版参看:https://github.com/ariya/phantomjs,下载地址为: https://phantomjs.org/download.html # wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-i686.tar.bz2 # tar -jxvf phantomjs-1.9.8-linux-i686.tar.bz2 # cp phantomjs-1.9.8-linux-i686/bin/phantomjs /bin/phantomjs 第二步中解压后bin目录下的 phantomjs 二进制文件即是可调用命令。 第三步是为了在以后调用命令时不必输入命令全路径。 2、调用 phantomjs的调用需要一个js脚本。这个js脚本接收两个参数,分别是网址url和快照文件名称filename,脚本snap.js内容如下: /* * desc: get snapshot from url * example: phantomjs snap.js http://www.baidu.com baidu.png */ var page = require('webpage').create(); var args = require('system').args; […]
Gideon