background preloader

New features

Facebook Twitter

Webpage screenshots with webkit | WebScraping.com. Webpage screenshots with webkit For a recent project I needed to render screenshots of webpages. Here is my solution using webkit: import sysimport timefrom PyQt4.QtCore import *from PyQt4.QtGui import *from PyQt4.QtWebKit import * class Screenshot(QWebView): def __init__(self): self.app = QApplication(sys.argv) QWebView. __init__(self) self. _loaded = False self.loadFinished.connect(self. _loadFinished) def capture(self, url, output_file): self.load(QUrl(url)) self.wait_load() # set to webpage size frame = self.page().mainFrame() self.page().setViewportSize(frame.contentsSize()) # render image image = QImage(self.page().viewportSize(), QImage.Format_ARGB32) painter = QPainter(image) frame.render(painter) painter.end() print 'saving', output_file image.save(output_file) def wait_load(self, delay=0): # process app events until page loaded while not self.

_loaded: self.app.processEvents() time.sleep(delay) self. Source code is available at my bitbucket account. Demos « Deep Learning. Accenture Interview Questions. Coca-Cola presents: The Social Robot. How can I take a screenshot/image of a website using Python. 5. Embedding Python in Another Application — Python v2.7.5 documentation. The previous chapters discussed how to extend Python, that is, how to extend the functionality of Python by attaching a library of C functions to it. It is also possible to do it the other way around: enrich your C/C++ application by embedding Python in it. Embedding provides your application with the ability to implement some of the functionality of your application in Python rather than C or C++. This can be used for many purposes; one example would be to allow users to tailor the application to their needs by writing some scripts in Python. You can also use it yourself if some of the functionality can be written in Python more easily.

Embedding Python is similar to extending it, but not quite. So if you are embedding Python, you are providing your own main program. A simple demo of embedding Python can be found in the directory Demo/embed/ of the source distribution. See also Python/C API Reference Manual The details of Python’s C interface are given in this manual. 5.1. 5.2. 5.3. 5.4. Create screenshots of a web page using Python and QtWebKit | Roland's Blog. Update 2009-10-03: For further development and improvements, contact me or have a look at this public github repository created by Adam Nelson. Update 2010-04-12: If you need flash support, you should have a look at the current github version of this script at mentioned above. We've extend the script a few month ago. From time to time you may want to create a screenshot of a web page from command line, for example if you wish to create thumbnails for your web-application.

So you might search for such a program and find tools like webkit2png, which is for Mac OS X only, or khtml2png, which requires a lot of KDE stuff to be installed on your server. But since Qt Software, formerly known als Trolltech, integrated Safari's famous rendering engine WebKit (which is based on Konqueror's khtml engine) into its framework, we are now able to make use of it with the help of some Python and PyQt4.

I assume that you have some basic knowledge of python. . #! Done.