Skip to content

Instantly share code, notes, and snippets.

@glarrain
Forked from eliezerfot123/screenshot_web.py
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glarrain/7ac126ac3fdb204f218a to your computer and use it in GitHub Desktop.
Save glarrain/7ac126ac3fdb204f218a to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
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()
# ajustado eel tamaño de página
frame = self.page().mainFrame()
size = frame.contentsSize()
# Añadiendo tamaño de ancho a la imagen
size.setWidth(2000)
self.page().setViewportSize(size)
# 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):
# eventos de aplicaciones de proceso hasta que la página cargue
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://www.google.com', 'website.png')
# Que viva Python Cariii--
# @eliezerfot123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment