Answer the question
In order to leave comments, you need to log in
PyQt5 QWebEngineView open page - how to get source code?
Good afternoon
everyone PyQt5 QWebEngineView open page
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import QWebEngineSettings, QWebEngineView, QWebEnginePage
from PyQt5.QtGui import QIcon
import PyQt5
import sys
class Main(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('Name')
self.setWindowIcon(QIcon('icon.png'))
web = QWebEngineView()
web.load(QUrl("https://google.com"))
html = web.page().toHtml()
self.btn = QPushButton('Button', self)
self.btn.resize(self.btn.sizeHint())
lay = QVBoxLayout(self)
lay.addWidget(self.btn)
lay.addWidget(web)
app = QApplication(sys.argv)
main = Main()
main.show()
app.exec_()
Answer the question
In order to leave comments, you need to log in
toHtml method is asynchronous, it needs a callback function as an argument, which will accept a string as input, which will be the page code
def processHTML(html):
print(html)
web.page().toHtml(processHTML)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question