Created
July 7, 2014 20:42
-
-
Save dublado/193b10eeadf5de120fa0 to your computer and use it in GitHub Desktop.
screenshot fullsize fullscreen screen capture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
from 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._loaded = False | |
def _loadFinished(self, result): | |
self._loaded = True | |
s = Screenshot() | |
s.capture('http://oppa.com.br/?lb=0', 'website.png') | |
s.capture('http://www.oppa.com.br/moveis', 'moveis.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment