linux命令行抓取网页快照图片,网页转pdf, 支撑flash显示-(xvfb+CutyCapt / wkhtmltopdf)...

本文详细介绍了如何在Ubuntu系统上安装Cutycapt和Headless WebKit,通过命令行操作进行网页截图,并提供了安装步骤、实践示例及替代工具wkhtmltopdf的使用方法。

 Install cutycapt and headless webkit on Ubuntu to take screenshots of other websites Just type ./install and it should install all the necessary libraries for you. At the last step, it will also take a screenshot of google and output it to example.png to see that everything worked.

 

install.sh:

#!/bin/bash
echo "now installing cutycapt"

sudo apt-get update -y
sudo apt-get install build-essential -y
sudo apt-get install xvfb -y
sudo apt-get install xfs xfonts-scalable xfonts-100dpi -y
sudo apt-get install libgl1-mesa-dri -y
sudo apt-get install subversion libqt4-webkit libqt4-dev g++ -y

mkdir ~/scripts
cd ~/scripts
svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt
cd cutycapt/CutyCapt

qmake
make

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

 

或者

 

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


Qt(CutyCapt是基于此框架开发的)

实践:


1.安装CutyCapt、Qt及相关软件包:

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:

apt-get install xvfb

 
3.抓取测试:

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

 

或者

 

cutycapt --url="http://google.com" --out=./google.jpg  

 

参考:

 

http://cutycapt.sourceforge.net/

 

 你也可以使用 wkhtmltopdf

 

用法:

#To convert a remote HTML file to PDF:
wkhtmltopdf http://www.google.com google.pdf

#To convert a local HTML file to PDF:
wkhtmltopdf my.html my.pdf

#You can also convert to PS files if you like:
wkhtmltopdf my.html my.ps

#The eler2.pdf sample file
wkhtmltopdf http://geekz.co.uk/lovesraymond/archive/eler-highlights-2008 eler2.pdf -H --outline

 

视频: http://www.youtube.com/watch?v=Oy3XjawQjlQ

 

3、安装中文字库  #很多体系是没有中文的,所以你要安装中文字库,不然网页会显示方块的

 

sudo apt-get install ttf-arphic-ukai ttf-arphic-uming
sudo apt-get install ttf-wqy-zenhei
sudo fc-cache -v
 

 

4、安装flash插件 #如今web网站很多多少都有flash,为了别呈现一个方块,就顺手安装上吧

sudo apt-get install flashplugin-nonfree

 

[root@yfw ~]# cd /opt/openfire/enterprise/spark/Spark [root@yfw Spark]# # 1. 创建提取目录 [root@yfw Spark]# cd /tmp [root@yfw tmp]# mkdir -p xvfb-extract && cd xvfb-extract [root@yfw xvfb-extract]# rm -rf * [root@yfw xvfb-extract]# [root@yfw xvfb-extract]# # 2. 解压 RPM 内容到当前目录 [root@yfw xvfb-extract]# rpm2cpio ../xorg-x11-server-Xvfb-1.20.11-2.el8.x86_64.rpm | cpio -idmv ./usr/bin/Xvfb ./usr/bin/xvfb-run ./usr/lib/.build-id ./usr/lib/.build-id/90 ./usr/lib/.build-id/90/ef040f79a6dc2a63bd97c6f8615551a9918520 ./usr/share/man/man1/Xvfb.1.gz 4104 blocks [root@yfw xvfb-extract]# [root@yfw xvfb-extract]# # 3. 查看是否成功提取出 Xvfb [root@yfw xvfb-extract]# ls -l usr/bin/Xvfb -rwxr-xr-x 1 root root 2091144 Jun 11 2021 usr/bin/Xvfb [root@yfw xvfb-extract]# # 输出应类似: [root@yfw xvfb-extract]# # -rwxr-xr-x 1 root root 298808 Jan 1 2021 usr/bin/Xvfb [root@yfw xvfb-extract]# [root@yfw xvfb-extract]# # 4. 复制到 openfire 用户 bin 目录 [root@yfw xvfb-extract]# su - openfire -c 'mkdir -p ~/bin' This account is currently not available. [root@yfw xvfb-extract]# cp usr/bin/Xvfb /home/openfire/bin/ cp: cannot create regular file '/home/openfire/bin/': Not a directory [root@yfw xvfb-extract]# chown openfire:openfire /home/openfire/bin/Xvfb chown: cannot access '/home/openfire/bin/Xvfb': No such file or directory [root@yfw xvfb-extract]# chmod +x /home/openfire/bin/Xvfb chmod: cannot access '/home/openfire/bin/Xvfb': No such file or directory [root@yfw xvfb-extract]# [root@yfw xvfb-extract]# # 5. 验证可执行性 [root@yfw xvfb-extract]# su - openfire -s /bin/bash -c 'which Xvfb; Xvfb -help | head -5' /usr/bin/which: no Xvfb in (/usr/local/ffmpeg/bin:/opt/spark/bin:=en_US.UTF-8:/usr/local/ffmpeg/bin) -bash: head: command not found -bash: Xvfb: command not found [root@yfw xvfb-extract]#
最新发布
10-31
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值