Ankit
Ankit

Reputation: 130

Implementing web inspection in browser using PyQt5

QtWebKit is no longer supported in PyQt5.

Although there are alternates to some of the classes of QtWebKit in QtWebEngineWidgets. But, i couldn't find any alternate to the QWebInspector class that is available in PyQt4.

Are there any such classes OR even any other option so that i can implement web inspector using PyQt5 ?

Edit: Qt5.6 and beyond has removed QtWebKitWidgets

Upvotes: 3

Views: 2241

Answers (2)

ekhumoro
ekhumoro

Reputation: 120608

I was somewhat surprised to find that QtWebKit is making a comeback. It is still not part of Qt-5.6 or Qt-5.7, but it seems that it may continue to be maintained as separate project. This means PyQt5 can continue to support QtWebKit, even though the official Qt5 docs say it has been removed.

Depending on your platform, this probably means you will need to install some extra packages if you want to use the "new" QtWebKit module in PyQt5.

PS:

As for QtWebEngine - if you're using ubuntu/debian, it seems you will have to wait for it to be supported. See Bug #1579265.

Upvotes: 2

eyllanesc
eyllanesc

Reputation: 243973

I show the following example to use QWebInspector in PyQt5 version 5.7.1

from PyQt5.QtCore import QUrl
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWebKitWidgets import QWebView, QWebInspector
from PyQt5.QtWidgets import QApplication, QSplitter, QVBoxLayout, QWidget


class Window(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent=parent)
        self.view = QWebView(self)
        self.view.settings().setAttribute(
            QWebSettings.DeveloperExtrasEnabled, True)
        self.inspector = QWebInspector()
        self.inspector.setPage(self.view.page())
        self.inspector.show()
        self.splitter = QSplitter(self)
        self.splitter.addWidget(self.view)
        self.splitter.addWidget(self.inspector)
        layout = QVBoxLayout(self)
        layout.addWidget(self.splitter)

if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    window = Window()
    window.view.load(QUrl('http://www.google.com'))
    window.show()
    sys.exit(app.exec_())

enter image description here

Upvotes: 2

Related Questions