Website to image
Question: I'm running Python 3.1 and you would call me an advanced novice :)

My question is simple: I'm trying to make a simple program which asks the
users for a URL (or multiple URLs) and then goes to the website and takes a
screenshot (of the whole page, not just what can be seen in the browser
without scrolling all the way down).

It's simpler then it sounds, I want to use an existing platform on the web,
similar to this:

    
    
    import subprocess
    MYFILENAME = "google_screen"
    MYURL = "www.google.com"
    subprocess.Popen(['wget', '-O', MYFILENAME+'.png', 'http://images.websnapr.com/?url='+MYURL+'&size=s&nocache=82']).wait()
    

Although this website does not work :(, I'm wondering is it possible to do it
with [this website](http://www.sciweavers.org/free-online-web-to-image) and if
so, how? If it is not possible, are there any alternatives?


Answer: There is a package called webkit2png that you can use for this, its located:
[here](https://github.com/paulhammond/webkit2png/)

More information on [this blog
post](http://rolandtapken.de/blog/2008-12/create-screenshots-web-page-using-
python-and-qtwebkit)

Example from blog post(copied to SO for preservation, read the blog post to
understand it if you have issues):

    
    
    #!/usr/bin/env python
    import sys
    import signal
    
    from PyQt4.QtCore import *
    from PyQt 4.QtGui import *
    from PyQt4.QtWebKit import QWebPage
    
    def onLoadFinished(result):
        if not result:
            print "Request failed"
            sys.exit(1)
    
        # Set the size of the (virtual) browser window
        webpage.setViewportSize(webpage.mainFrame().contentsSize())
    
        # Paint this frame into an image
        image = QImage(webpage.viewportSize(), QImage.Format_ARGB32)
        painter = QPainter(image)
        webpage.mainFrame().render(painter)
        painter.end()
        image.save("output2.png")
        sys.exit(0)
    
    
    app = QApplication(sys.argv)
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    
    webpage = QWebPage()
    webpage.connect(webpage, SIGNAL("loadFinished(bool)"), onLoadFinished)
    webpage.mainFrame().load(QUrl("http://www.google.com"))
    
    sys.exit(app.exec_())
    

Edit: [Link to the pyqt4 download
page](http://www.riverbankcomputing.co.uk/software/pyqt/download)

