Loading frame page for screenshot

I have an application that displays a webpage in an iframe, and then loads the X number of images in a div that overlays the frame.

So, I have this python script that loads the url and takes a screenshot. It works on regular web pages, but I think the frame discards it. Below is my code and a link to a snapshot of it.

#!/usr/bin/env python
import sys
import signal

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import QWebPage

def onLoadFinished(result):
    if not result:
        print "Request failed"
        sys.exit(1)

    #screen = QtGui.QDesktopWidget().screenGeometry()
    size = webpage.mainFrame().contentsSize()
    # Set the size of the (virtual) browser window
    webpage.setViewportSize(webpage.mainFrame().contentsSize())

    # Paint this frame into an image
    image = QImage(webpage.viewportSize(), QImage.Format_ARGB32)
    painter = QPainter(image)
    webpage.mainFrame().render(painter)
    painter.end()
    image.save("/var/www/html/output.png")
    sys.exit(0)


qtargs = [sys.argv[0]]
qtargs.append("-display")
qtargs.append(":0")

app = QApplication(qtargs,True)
#app = QApplication(sys.argv)
signal.signal(signal.SIGINT, signal.SIG_DFL)

webpage = QWebPage()
webpage.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
webpage.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
webpage.connect(webpage, SIGNAL("loadFinished(bool)"), onLoadFinished)
webpage.mainFrame().load(QUrl("http://localhost/heatmap"))

sys.exit(app.exec_())

Screenshot: http://img28.imageshack.us/img28/7506/outputc.png

, , iframe div . - , ? Qt.ScrollbarAlwaysOff . "-" -, - , , .

webpage.mainFrame(). contentsSize() , PyQt4.QtCore.QSize(400, 158)

- www.google.com, PyQt4.QtCore.QSize(617, 573)

, - , contentSize(). , ?

+3
1

, QWebPage.setPreferredContentsSize() . , . ( , )

, .

0

Source: https://habr.com/ru/post/1750725/


All Articles