Код: Выделить всё
import sys
import time
from PyQt6.QtCore import *
from PyQt6.QtGui import *
from PyQt6.QtWidgets import QApplication, QWidget
from PyQt6.QtWebEngineWidgets import QWebEngineView
class Screenshot(QWebEngineView):
def __init__(self):
self.app = QApplication(sys.argv)
QWebEngineView.__init__(self)
self._loaded = False
self.loadFinished.connect(self._loadFinished)
def capture(self, url, output_file):
self.resize(QSize(1024, 768))
self.load(QUrl(url))
self.wait_load()
image = QImage(self.size(), QImage.Format.Format_ARGB32)
painter = QPainter(image)
self.render(painter)
painter.end()
image.save(output_file)
def wait_load(self, delay=0):
# process app events until page loaded
while not self._loaded:
self.app.processEvents()
time.sleep(delay)
self._loaded = False
def _loadFinished(self, result):
self._loaded = True
s = Screenshot()
s.capture("https://www.google.com", "screenshot.png")
< /code>
Я попробовал вариации кода, где Qtwebengineview отображается в окне приложения, и эта часть работает. WATE_LOAD
Подробнее здесь: https://stackoverflow.com/questions/793 ... ways-empty