Note that there are some explanatory texts on larger screens.

plurals
  1. POQtWebKit: Is it possible to get events for files downloaded by a webpage?
    text
    copied!<p>I'm having some difficulty with this, but basically load a page into a QWebView is it possible to get events on the content that gets loaded in the process of rendering the page?</p> <p>I'm using PySide, so assuming you already have a QWebView as 'w'</p> <pre><code>w.load('http://www.unicorns-are-awesome.com/index.html') </code></pre> <p>And the contents of that index.html look like:</p> <pre><code>&lt;html&gt; ... &lt;head&gt; &lt;script src="something.js"&gt; &lt;/head&gt; &lt;body&gt; &lt;img src="unicorns.jpg"&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The QWebView has to download both <strong>something.js</strong> and <strong>unicorns.jpg</strong> - but there so far does not appear to be any obvious way to get downloadRequest events for these subordinate downloads.</p> <p>The only time that 'downloadRequest' is emitted by w.page() is when you change the URL in the QtWebView, i.e. you only get updates for what would be in the 'Location' bar.</p> <p>How can you get notified for <strong>every</strong> element that a webpage downloads in your QtWebView?</p> <h3>Update: NetworkAccessManager Implementation:</h3> <pre><code>from MainWindow import MainWindow from PySide.QtGui import QApplication from PySide.QtCore import QCoreApplication from PySide.QtWebKit import QWebView, QWebSettings from PySide.QtNetwork import QNetworkReply class TransferMonitor(object): def __init__(self): a = MainWindow._instance # "singleton" b = a.findChild(QWebView, "browser") nm = b.page().networkAccessManager() nm.finished[QNetworkReply].connect( self.dump_url ) def dump_url(self, reply): # This is probably unnecessary, but # I wanted to be 100% sure that every get # was 'fresh'. QWebSettings.clearMemoryCaches() # For now all we really do is just dump URLs # as they're processed. Perhaps later we will intercept. print reply.url().toString() </code></pre>
 

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