仅将下面的代码与特定的网址一起使用时,我遇到了问题:
import sys
from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QUrl
from PyQt4.QtWebKit import QWebView,QWebSettings
class Browser(QWebView):
def __init__(self):
QWebView.__init__(self)
Settings = self.settings()
Settings.setAttribute(QWebSettings.JavascriptEnabled, True)
Settings.setAttribute(QWebSettings.JavaEnabled, True)
Settings.setAttribute(QWebSettings.PluginsEnabled, True)
Settings.setAttribute(QWebSettings.AutoLoadImages, True)
self.loadFinished.connect(self._result_available)
def _result_available(self, ok):
frame = self.page().mainFrame()
print unicode(frame.toHtml()).encode('utf-8')
if __name__ == '__main__':
app = QApplication(sys.argv)
view = Browser()
from_url=True
url_to_view='https://www.twitch.tv/'
if from_url==True:
view.load(QUrl(url_to_view))
view.show()
app.exec_()
运行此代码时,我得到一个空白页,并且出现此错误:
QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once.
QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once.
这很奇怪,因为我仅在https://www.twitch.tv/网址上遇到了此问题。我曾尝试用https://www.google.com或其他任何方式替换url,但效果很好。
我原本以为它与python2
和PyQt4
相关,但是在python3
和PyQt5
实现上运行时却遇到了相同的问题
有人可以帮助我使用pyqt正确加载页面吗?