【发布时间】:2018-07-05 17:06:25
【问题描述】:
我正在尝试增加渲染 Javascript 的额外时间,我知道我需要使用 Qtimer,但我现在不知道如何以正确的方式进行编码。
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
class Client(QWebPage):
def __init__(self, url):
self.app = QApplication(sys.argv)
QWebPage.__init__(self)
self.loadFinished.connect(self.finished_loading)
self.userAgentForUrl(url)
self.timer = QTimer()
self.timer.singleShot(15000, self.finished_loading)
self.mainFrame().load(QUrl(url))
self.app.exec_()
def userAgentForUrl(self, url):
return 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0'
def finished_loading(self,url):
self.app.quit()
url=#URL
client_response = Client(url)
source = client_response.mainFrame().toHtml()
print(source.encode('utf-8'))
【问题讨论】:
标签: python python-3.x pyqt pyqt4 qtwebkit