views:

138

answers:

1

I've got thousands of urls from many hosts I need to screenshot.

I can use the lib fine from the command line, but how can I integrate it into my code so I can take multiple screenshots simultaneously?

I think it's something to do with xvfb as with the answer to this question: http://stackoverflow.com/questions/1747022/how-to-kill-headless-x-server-started-via-python but I'm not sure what exactly.

A: 

Probably something like this (untested):

from webkit2png import WebkitRenderer, init_qtgui
from PyQt4.QtCore import QTimer

def renderer_func():   
    renderer = WebkitRenderer()
    renderer.width = 800
    renderer.height = 600
    renderer.timeout = 10
    renderer.wait = 1
    renderer.format = "png"
    renderer.grabWholeWindow = False

    outfile = open("stackoverflow.png", "w")
    renderer.render_to_file(url="http://stackoverflow.com", file=outfile)
    outfile.close()

app = init_qtgui()
QTimer.singleShot(0, renderer_func)
sys.exit(app.exec_())

This was shamelessly ripped off from the source code of webkit2png.py.

Tamás
Thanks, but the part that I am having trouble with is using Xvfb
oldfellow