I tried to use pyqt5
to get html of webpages.
However, when I used it for a few times, it crashed.
Here is my code.
It is a simple for
loop to get the google
html.
How to solve this problem?
Thank you.
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView
import os
class Render(QWebEngineView):
def __init__(self, url):
self.html = None
self.app = QApplication(sys.argv)
QWebEngineView.__init__(self)
self.loadFinished.connect(self._load_finished)
self.load(QUrl(url))
self.mHtml = ""
self.app.exec_()
def _load_finished(self):
self.page().toHtml(self.callable)
def callable(self, data):
self.mHtml = data
self.app.quit()
os.system("taskkill /f /im qtwebengineprocess.exe")
url = 'https://www.google.com'
for i in range(10):
result = Render(url)