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

推荐订阅源

WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
Apple Machine Learning Research
Apple Machine Learning Research
O
OpenAI News
酷 壳 – CoolShell
酷 壳 – CoolShell
The GitHub Blog
The GitHub Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 聂微东
Engineering at Meta
Engineering at Meta
W
WeLiveSecurity
Hacker News: Ask HN
Hacker News: Ask HN
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
D
Docker
F
Full Disclosure
AI
AI
罗磊的独立博客
博客园 - 【当耐特】
U
Unit 42
S
SegmentFault 最新的问题
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Palo Alto Networks Blog
博客园_首页
H
Help Net Security
量子位
月光博客
月光博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 司徒正美
F
Fortinet All Blogs
D
DataBreaches.Net
B
Blog RSS Feed
Webroot Blog
Webroot Blog
TaoSecurity Blog
TaoSecurity Blog
S
Secure Thoughts
爱范儿
爱范儿
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Attack and Defense Labs
Attack and Defense Labs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
C
CERT Recently Published Vulnerability Notes
Martin Fowler
Martin Fowler
Blog — PlanetScale
Blog — PlanetScale
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Securelist

博客园 - xin478

使用nfs共享session文件导致 session_start异常缓慢问题 nginx proxy_pass末尾神奇的/ 在php中使用SMTP通过密抄批量发送邮件续:修正 无聊闲做,从使用PHP数组实现约瑟夫环问题谈性能 在php中使用SMTP通过密抄批量发送邮件 使用VisualStudio开发php mysql常用的hint[转] php垃圾代码优化那档子事 配置windows下php+apache+mysql环境 惨啊!mp4固件升级惊魂 用PHP实现POP3邮件的收取 希捷酷鱼12 500G的确有问题,好惨啊 解决IE6下PNG透明问题,支持平铺背景图片 VS.PHP with VS2008 in windows7 windows7蓝屏啦 mysql使用rand随机查询记录效率测试 特殊字符的html编码转化 - xin478 - 博客园 asp.net页面事件执行顺序 在visual studio中随意更改中文字体的方法
linux下抓取网页截图
xin478 · 2012-06-06 · via 博客园 - xin478

项目需要抓取指定网址截图的功能,linux下正好有这样的工具,最后选定用phantomjs,这是基于Javascript驱动的命令行webkit引擎,轻量级,安装简单,开发快速,渲染速度较快的无界面的webkit浏览器

更多介绍可以参考 http://code.google.com/p/phantomjs

http://code.google.com/p/phantomjs/downloads/list 下载源码包,我下的是phantomjs-1.5.0-source.tar.gz

# wget http://code.google.com/p/phantomjs/downloads/detail?name=phantomjs-1.5.0-source.tar.gz&can=2&q=

# cd phantomjs-1.5.0/

# ./build.sh

漫长等待后,编译结束。这个不需要在额外安装qt之类的,比较方便。

新建一个js脚本,内容如下:

 
var page = new WebPage(),
    address, output, size;
 
if (phantom.args.length < 2 || phantom.args.length > 3) {
    console.log('Usage: rasterize.js URL filename');
    phantom.exit();} else {
    address = phantom.args[0];
    output = phantom.args[1];
    page.viewportSize = { width: 600, height: 600 };
    page.open(address, function (status) {
        if (status !== 'success') {
            console.log('Unable to load the address!');
        } else {
            window.setTimeout(function () {
                page.render(output);
                phantom.exit();
            }, 200);
        }
    });}

保存为snap.js

需要截图的时候,执行如下命令:

# ./bin/phantomjs snap.js http://qq.com qq.com.png

即生成了截图文件 qq.com.png。

目前,phantomjs还是需要x-server的依赖才可以运行的,因此需要安装xfvb。