pyqt5中无法在循环中使用QWebEnginePage

时间:2019-03-09 18:09:03

标签: pyqt5 qwebenginepage

尝试这样的简单提取循环(我认为是这样):

import sys
from PyQt5.QtWebEngineWidgets import QWebEnginePage
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl
from time import sleep


class Page(QWebEnginePage):
    def __init__(self, url):
        self.app = QApplication(sys.argv)
        QWebEnginePage.__init__(self)
        self.html = ''
        self.loadFinished.connect(self._on_load_finished)
        self.load(QUrl(url))
        self.app.exec_()


    def _on_load_finished(self):
        sleep(7)
        self.html = self.toHtml(self.Callable)
        print('Load finished')


    def Callable(self, html_str):
        self.html = html_str
        self.app.quit()


for _ in range(4):
    Page('https://www.bbc.com/')

在具有Python 3.7.2,PyQt 5.12.2的Linux上,该循环崩溃并显示为:

Received signal 11 SEGV_MAPERR 000000000250

但是,如果我删除循环并在此代码中启动单个Page(),然后从终端多次调用它,则它将正常工作。

有没有办法使循环起作用?

0 个答案:

没有答案