Skip to content

Instantly share code, notes, and snippets.

@eliezerfot123
Created August 27, 2013 14:08
Show Gist options
  • Save eliezerfot123/6354014 to your computer and use it in GitHub Desktop.
Save eliezerfot123/6354014 to your computer and use it in GitHub Desktop.
Programa que permite hace una captura de una website...
# -*- 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