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

推荐订阅源

P
Proofpoint News Feed
The Last Watchdog
The Last Watchdog
Security Latest
Security Latest
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
H
Help Net Security
T
The Exploit Database - CXSecurity.com
Know Your Adversary
Know Your Adversary
博客园_首页
S
Securelist
S
Schneier on Security
G
GRAHAM CLULEY
Cisco Talos Blog
Cisco Talos Blog
V
Visual Studio Blog
博客园 - 叶小钗
C
Cybersecurity and Infrastructure Security Agency CISA
有赞技术团队
有赞技术团队
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Azure Blog
Microsoft Azure Blog
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
Stack Overflow Blog
Stack Overflow Blog
量子位
L
Lohrmann on Cybersecurity
Hugging Face - Blog
Hugging Face - Blog
Engineering at Meta
Engineering at Meta
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
A
Arctic Wolf
P
Privacy & Cybersecurity Law Blog
Simon Willison's Weblog
Simon Willison's Weblog
S
SegmentFault 最新的问题
The Hacker News
The Hacker News
罗磊的独立博客
博客园 - 司徒正美
D
Darknet – Hacking Tools, Hacker News & Cyber Security
博客园 - 【当耐特】
Microsoft Security Blog
Microsoft Security Blog
K
Kaspersky official blog
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
L
LINUX DO - 热门话题
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
V2EX
V
Vulnerabilities – Threatpost
AWS News Blog
AWS News Blog
小众软件
小众软件
Project Zero
Project Zero

博客园 - 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。