I’just started learning PyQt4, and playing with signals and slots,
Please help me to fix my code in such a way that after site is fully downloaded, it will print html of this webpage. Right now it just stops after “load finished”
my code:
#! /usr/bin/env python2.7
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
import sys
class Browser(QObject):
def __init__(self):
QObject.__init__(self)
def print_percent(self, percent):
print percent
def print_load_finished(self):
print 'Load Finished'
self.print_html
def print_html(self, ok):
frame = QWebView.page().mainFrame()
print unicode(frame.toHtml()).encode('utf-8')
if __name__=='__main__':
app = QApplication(sys.argv)
view = QWebView()
br = Browser()
url = QUrl('http://python.org')
view.loadFinished.connect(br.print_load_finished)
view.loadProgress.connect(br.print_percent)
view.load(url)
view.show()
app.exec_()
You need to call
print_htmlmethod e.g.note
()at the end ofprint_htmlBUT then it still won’t work anyway as your
print_htmldoesn’t have access to view, you can pass view to it, but it not a right way to do Object oriented programming. You should be deriving Browser from may beQWebViewand bind to events in__init__, so it should be something like this