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 file
使用举例:
使用之前安装依赖的包
sudo apt-get install python-qt4
OK,可以用了,假如在用ubuntu桌面版的话就很简单了
#加上运行权限
chmod +x ./webkit2png.py
#高度设置为0,就可以获得整个页面的截图了
./webkit2png.py -g 1024 0 http://www.baidu.com -o test.png
假如运行在服务器上,没有x环境,则需要安装一些额外的依赖包
#安装xvfb用于虚拟X环境
apt-get install xvfb
#安装中文字体
apt-get install xfonts-wqy
#配置字体
fontconfig-voodoo -f -s zh_CN
运行时需要加额外的参数