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

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 https://bluehua.org -o test.png

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

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

运行时需要加额外的参数

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

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

———–
post by gmail~


已发布

分类

,

来自

标签:

评论

《 “一个python版的开源web截图工具:python-webkit2png” 》 有 3 条评论

  1. […] 同事用python抓各大andriod市场的页面分析软件下载量,后来发现andriod market的数据是通过ajax加载的,而且貌似加密过了。后来俺发现了phantomjs这个命令行的webkit,在可以在命令行渲染网页,这样不论数据怎么加载,怎么加密,对于标准的浏览器都无能为力了。软件的原理跟以前介绍的一个命令行web截图工具一样,内嵌一个qt4的webkit,然后渲染到xvfb虚拟出的xserver上。不同是这个提供了js的api,用起来方便,可以用来做爬虫,站点监控,服务端截图。 […]

  2. cheney 的头像

    不支持截取js加载后的页面…[bofu::bofu3_14.gif]

  3. ivanlw 的头像
    ivanlw

    楼主按照您的操作,提示错误……
    from: can’t read /var/mail/PyQt4.QtCore
    from: can’t read /var/mail/PyQt4.QtGui
    from: can’t read /var/mail/PyQt4.QtWebKit
    from: can’t read /var/mail/PyQt4.QtNetwork
    ./webkit2png.py: line 35: syntax error near unexpected token `(‘
    ./webkit2png.py: line 35: `class WebkitRenderer(QObject):’

    而看了github上的说明,要用这个命令
    on a headless server run: xvfb-run –server-args=”-screen 0, 640x480x24″ python webkit2png-simple.py

    但是却提示xvfb启动失败,请问有什么方法解决吗?

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据