Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading page with frames for a screenshot
    text
    copied!<p>I have an app that renders a web page in a iframe, and then loads X number of images in a div that overlays the frame. </p> <p>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 is throwing it off. Below is my code, and a link to the screenshot it's taking.</p> <pre><code>#!/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_()) </code></pre> <p>Screenshot taken: <a href="http://img28.imageshack.us/img28/7506/outputc.png" rel="nofollow noreferrer">http://img28.imageshack.us/img28/7506/outputc.png</a></p> <p>As you can see in the above image, the page is shrunk into a small image with scroll bars, not showing the entire page with the iframe and div on top of it. Do I somehow need to load the stylesheets or force it to render like it is in the browser? Qt.ScrollbarAlwaysOff doesn't really seem to be working in my instance. The "placeholder text" is part of the webpage, and the image is what is making it kind of grey, with a blue smug and color key in the top left.</p> <p>When I print the contents of webpage.mainFrame().contentsSize() for my app, I get PyQt4.QtCore.QSize(400, 158)</p> <p>But when I render something like www.google.com, I get PyQt4.QtCore.QSize(617, 573)</p> <p>So something isn't being loaded properly to mess up the contentsSize(). Ideas on where I have gone wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload