webkit python_一个python版的开源web截图工具:python-webkit2png

python-webkit2png是一个使用PyQT4的QtWebkit实现的命令行工具,用于服务器端的网页截图。它支持多种参数,如设置窗口大小、等待时间、输出格式等。在无X环境的服务器上,需要安装xvfb和中文字体来配合使用。
摘要由CSDN通过智能技术生成

http://github.com/AdamN/python-webkit2png/

一个使用pyqt4里的QtWebkit实现的命令行的web截图软件,可用于服务器端的web截图

貌似是个比较新的项目,以前找过类似的工具,没有多好用的,但是这个真的很好用,看一下参数就知道了

Creates a screenshot of a website using QtWebkit.This program comes with

ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to

redistribute it under the terms of the GNU General Public License v2.

Options:

--version show program's version number and exit

-h, --help show this help message and exit

-x WIDTH HEIGHT, --xvfb=WIDTH HEIGHT

Start an 'xvfb' instance with the given desktop size.

-g WIDTH HEIGHT, --geometry=WIDTH HEIGHT

Geometry of the virtual browser window (0 means

'autodetect') [default: (0, 0)].

-o FILE, --output=FILE

Write output to FILE instead of STDOUT.

-f FORMAT, --format=FORMAT

Output image format [default: png]

--scale=WIDTH HEIGHT Scale the image to this size

--aspect-ratio=RATIO One of 'ignore', 'keep', 'crop' or 'expand' [default:

none]

-F FEATURE, --feature=FEATURE

Enable additional Webkit features ('javascript',

'plugins')

-w SECONDS, --wait=SECONDS

Time to wait after loading before the screenshot is

taken [default: 0]

-t SECONDS, --timeout=SECONDS

Time before the request will be canceled [default: 0]

-W, --window Grab whole window instead of frame (may be required

for plugins)

--style=STYLE Change the Qt look and feel to STYLE (e.G. 'windows').

-d DISPLAY, --display=DISPLAY

Connect to X server at DISPLAY.

--debug Show debugging information.

--log=LOGFILE Select the log output fileCreates a screenshot of a website using QtWebkit.This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under the terms of the GNU General Public License v2. Options: --version show program's version number and exit -h, --help show this help message and exit -x WIDTH HEIGHT, --xvfb=WIDTH HEIGHT Start an 'xvfb' instance with the given desktop size. -g WIDTH HEIGHT, --geometry=WIDTH HEIGHT Geometry of the virtual browser window (0 means 'autodetect') [default: (0, 0)]. -o FILE, --output=FILE Write output to FILE instead of STDOUT. -f FORMAT, --format=FORMAT Output image format [default: png] --scale=WIDTH HEIGHT Scale the image to this size --aspect-ratio=RATIO One of 'ignore', 'keep', 'crop' or 'expand' [default: none] -F FEATURE, --feature=FEATURE Enable additional Webkit features ('javascript', 'plugins') -w SECONDS, --wait=SECONDS Time to wait after loading before the screenshot is taken [default: 0] -t SECONDS, --timeout=SECONDS Time before the request will be canceled [default: 0] -W, --window Grab whole window instead of frame (may be required for plugins) --style=STYLE Change the Qt look and feel to STYLE (e.G. 'windows'). -d DISPLAY, --display=DISPLAY Connect to X server at DISPLAY. --debug Show debugging information. --log=LOGFILE Select the log output fileCopy Code

使用举例:

使用之前安装依赖的包

sudo apt-get install python-qt4sudo apt-get install python-qt4Copy Code

OK,可以用了,假如在用ubuntu桌面版的话就很简单了

#加上运行权限

chmod +x ./webkit2png.py

#高度设置为0,就可以获得整个页面的截图了

./webkit2png.py -g 1024 0 http://bluehua.org -o test.png#加上运行权限 chmod +x ./webkit2png.py #高度设置为0,就可以获得整个页面的截图了 ./webkit2png.py -g 1024 0 http://bluehua.org -o test.pngCopy Code

假如运行在服务器上,没有x环境,则需要安装一些额外的依赖包

#安装xvfb用于虚拟X环境

apt-get install xvfb

#安装中文字体

apt-get install xfonts-wqy

#配置字体

fontconfig-voodoo -f -s zh_CN#安装xvfb用于虚拟X环境 apt-get install xvfb #安装中文字体 apt-get install xfonts-wqy #配置字体 fontconfig-voodoo -f -s zh_CNCopy Code

运行时需要加额外的参数

#x选项用于指定虚拟出来的X桌面的尺寸

./webkit2png.py -x 1024 768 -g 1024 0 http://bluehua.org -o test.png#x选项用于指定虚拟出来的X桌面的尺寸 ./webkit2png.py -x 1024 768 -g 1024 0 http://bluehua.org -o test.pngCopy Code

恩,其实我找这个东西的目的是想在服务器端获取一个页面的实际渲染宽度,目的达成~

———–

post by gmail~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值