linux命令行抓取网页快照(xvfb+CutyCapt)

linux命令行抓取网页快照-(xvfb+CutyCapt)
又一个 WordPress 博客
Browse: Home / 2009 / 十一月 / linux命令行抓取网页快照-(xvfb+CutyCapt)
linux命令行抓取网页快照-(xvfb+CutyCapt)

By saymoon on 2009年11月13日
目的:

在一台没有安装X-server的Debian服务器上实现命令行抓取网页快照
软件:

xvfb(在命令行下实现对X-server的模拟,渲染图形进行缓存)-在没有安装X-Server的环境下提供图像渲染
CutyCapt(模拟浏览器对网页进行下载、HTML、css渲染、Javascript执行,并将最终渲染完成的网页进行快照)- 主力干将
Qt(CutyCapt是基于此框架开发的)

实践:

1.安装CutyCapt、Qt及相关软件包:
帮助
1
2
3
4
5

sudo apt-get install subversion libqt4-webkit libqt4-dev g++
svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt
cd cutycapt/CutyCapt
qmake
make

2.安装xvfb:
帮助
1

apt-get install xvfb

3.抓取测试:
帮助
1

xvfb-run --server-args="-screen 0, 1024x768x24" ./CutyCapt --url=http://www.zol.com.cn --out=zol.png

发现抓到的中文网页时乱码:

中文网页快照乱码

4.折腾了半天,原来是没有安装中文字体,安装中文字体,再抓~~
网页快照最终版
总结:

基本实现了通过linux命令行实现网页快照抓取的功能,但是CutyCapt对Javascript的解析能力还是有限,从上图可以看出通过swfobject加载的flash都没有被渲染出来。以后有空会尝试用Firefox直接做渲染抓取。
参考链接:

http://cutycapt.sourceforge.net/
http://www.x.org/archive/X11R6.8.2/doc/Xvfb.1.html
http://www.yeeach.com/tag/screenshot/
http://hi.baidu.com/pkubuntu/blog/item/7dcc064ff0246a3eaec3abe2.html
http://qt.nokia.com/
http://en.wikipedia.org/wiki/Xvfb

安装中文字体:http://hi.baidu.com/spiritualcity/blog/item/96369c2afa8740fde6cd40d2.html
Linux中文内码控制方案:http://zhcon.sourceforge.net/index_cn.html

Posted in linux | Tagged cutycapt, debian, xvfb, 快照 | 12 Responses
12 responses to “linux命令行抓取网页快照-(xvfb+CutyCapt)”

bill
bill 2009年12月3日 at 12:58 上午 | Permalink

sudo apt-get install subversion libqt4-webkit libqt4-dev g++
svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt
cd cutycapt/CutyCapt
qmake
make

为什么我执行这个的时候。前两行都不能正确执行呢。我通过下载的方式下载了cutycapt,解压后运行make 也会报很多错。。请指教!
bill
bill 2009年12月3日 at 1:00 上午 | Permalink

Google搜到一个网页,也是我这样的错误。但是没看到有好的解决方法。我QT也安装了。gcc也都装了。
bill
bill 2009年12月3日 at 1:02 上午 | Permalink

因为没有成功安装Cutycapt,所以执行 xvfb-run –server-args=”-screen 0, 1024x768x24″ ./CutyCapt –url=http://www.google.com –out=example.png 后,也无法正确得到结果。困扰了我一天了。望指教!
bill
bill 2009年12月8日 at 8:09 下午 | Permalink

自己弄好了。呵呵。就差安装中文字体了
bill
bill 2009年12月8日 at 11:08 下午 | Permalink

对了,那个控制尺寸的,是不是不好用?
screen 0, 1024x768x24

无论改成什么,抓到的都是那个页面实际大小
Charly
Charly 2010年01月5日 at 1:39 上午 | Permalink

生成了一个空白图,昨回事呢?
timberland
timberland 2010年02月19日 at 1:19 上午 | Permalink

嘿嘿。。。
我又來了。。。
前來看望問候博主。。。
欣賞博主精文。。。
祝健康、幸福、快樂。。。
期待博主新作!。。。
在线网页截图实现技术 | Hi Java!
在线网页截图实现技术 | Hi Java! 2010年04月20日 at 4:29 上午 | Permalink

[...] http://blog.saymoon.com/2009/11/take-snapshot-in-linux-command-line/ [...]
bill
bill 2010年07月12日 at 7:52 下午 | Permalink

好端端的突然又不好用了。生成的都是空白页。。诡异啊!
道茶
道茶 2010年10月9日 at 8:24 上午 | Permalink

我连空白页面都没有
/usr/local/bin/xvfb-run: line 168: 23696 Segmentation fault DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE “$@” 2>&1

只有这个错误
daniel
daniel 2011年09月14日 at 11:50 下午 | Permalink

WIN2003里也乱码,怎么办?
oscar
oscar 2011年10月8日 at 11:56 下午 | Permalink

谢谢楼主,测试成功,不过
2.安装xvfb:不能自动成功

apt-get install xvfb

最后在http://packages.debian.org/zh-cn/lenny/xvfb
下载xvfb包 就可以了


原文地址:https://www.cnblogs.com/lexus/p/2224934.html