I am loading a webpage in PySide. I want to be able to see if it has loaded successfully without errors. If I get an error, then I want to know about it. I can not simply use the "success" parameter to the load finished signal, as it seems to always indicate success. The only way I know how to do it, is to do something like this:
class WebPageResourceTracker(
PySide.QtCore.QObject
):
def __init__(self, url):
PySide.QtCore.QObject.__init__(self)
self.page = PySide.QtWebKit.QWebPage()
self.frame = self.page.currentFrame()
# The reason for the lambda is that otherwise I get this:
#ASSERT: "self" in file /var/tmp/portage/dev-python/pyside-1.1.0/work/pyside-qt4.7+1.1.0/libpyside/signalmanager.cpp, line 534
self.frame.loadFinished.connect(lambda ok: self.onLoadFinished(ok))
self.page.networkAccessManager().finished.connect(lambda reply: self.onResourceFinished(reply))
self.frame.setUrl(
PySide.QtCore.QUrl(
url,
)
)
def onLoadFinished(self, ok):
print 'onLoadFinished', ok
def onResourceFinished(self, reply):
print 'onResourceFinished', reply.url().toString(), reply.error()
import sys
from PySide import QtGui
app = QtGui.QApplication(sys.argv)
#WebPageResourceTracker("http://google.com")
WebPageResourceTracker(
"http://migration.tanagerproductions.com/broken.html"
)
sys.exit(app.exec_())
But, I would imagine there would be a way to directly access a list of resources for the page, because the webkit inspector, can list off resources...
Bonus: I would also like to know if there is any JavaScript errors in the page, how would I do this?