I using pyqt5 for taking the screenshot to the URL. it's the react component. it takes the screenshot only component. don't wait till the API response. wanna take a screenshot after get the API response.
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt, QUrl, QTimer
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings
class Screenshot(QWebEngineView):
def capture(self, url, output_file):
self.output_file = output_file
self.load(QUrl(url))
self.loadFinished.connect(self.on_loaded)
self.setAttribute(Qt.WA_DontShowOnScreen)
self.show()
def on_loaded(self):
size = self.page().contentsSize().toSize()
self.resize(size)
qt = QTimer()
qt.setInterval(8000)
qt.setSingleShot(True)
qt.singleShot(8000, self.take_screenshot)
def take_screenshot(self):
self.grab().save(self.output_file, b'PNG')
self.app.quit()
app = QApplication([])
s = Screenshot()
s.app = app
s.capture('https://doc.qt.io/qt-5/qtimer.html', 'webpage20.png')
app.exec_()
Note: Under s.capture
param URL is just for the example purpose.