我刚开始学习 PyQt4,并玩信号和插槽,请帮助我修复我的代码,以便在站点完全下载后,它将打印此网页的 html。现在它只是在“加载完成”后停止
我的代码:
#! /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_()