一个python版的开源web截图工具:python-webkit2png
http://github.com/AdamN/python-webkit2png/
一个使用pyqt4里的QtWebkit实现的命令行的web截图软件,可用于服务器端的web截图
貌似是个比较新的项目,以前找过类似的工具,没有多好用的,但是这个真的很好用,看一下参数就知道了
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 p_w_picpath format [default: png]
--scale=WIDTH HEIGHT Scale the p_w_picpath 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 withABSOLUTELY NO WARRANTY. This is free software, and you are welcome toredistribute 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 p_w_picpath format [default: png] --scale=WIDTH HEIGHT Scale the p_w_picpath 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
使用举例:
使用之前安装依赖的包
OK,可以用了,假如在用ubuntu桌面版的话就很简单了
#加上运行权限chmod +x ./webkit2png.py
#高度设置为0,就可以获得整个页面的截图了
./webkit2png.py -g10240 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-getinstall xvfb
#安装中文字体
apt-getinstall 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 -x1024768-g10240 http://bluehua.org -o test.png#x选项用于指定虚拟出来的X桌面的尺寸./webkit2png.py -x 1024 768 -g 1024 0 http://bluehua.org -o test.pngCopy Code
恩,其实我找这个东西的目的是想在服务器端获取一个页面的实际渲染宽度,目的达成~