1

I am newbie, I want to create a jpg or png image of a web page whith PyQt4, so that you understand me for example something like this.

This script works perfect:

import sys
import time
import os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *

width= int(530)
height=int(1060)



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()

        time.sleep(2)

        # set to webpage size
        frame = self.page().mainFrame()

        self.page().setViewportSize(QSize(width, height,))


        # render image
        image = QImage(self.page().viewportSize(), QImage.Format_ARGB32)
        painter = QPainter(image)
        frame.render(painter)
        painter.end()
        print ('Guardada'), 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

filename = "capture"


s = Screenshot()
s.capture('http://www.filmaffinity.com/es/main.html', filename+(time.strftime("-%H-%M-%S"))+".png")

This captures me from above the page 530 px width x 1060px height, that's fine, but I want the capture start from below the web and more extended, I mean a certain area of the web,

such as this image

How can I modify the script?

Thanks

Samuel82
  • 121
  • 4

0 Answers0