首页 > 解决方案 > 空白页面和错误,只有一个特定的 url,在 python 中使用 pyqt webview

问题描述

仅将以下代码与特定 URL 一起使用时,我遇到了问题:

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,它工作正常。

我期待它与python2and相关,但是在运行和实现PyQt4时我遇到了同样的问题python3PyQt5

有人可以帮助我用 pyqt 正确加载页面吗?

标签: pythonpyqt4pyqt5qtwebkitqwebview

解决方案


推荐阅读