找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3551|回复: 0

[求助] PyQt5 的 segmentation fault (core dumped) 错误

0

主题

0

帖子

0

积分

贫民

积分
0
无尾壁虎 发表于 2019-11-15 18:27:23 | 显示全部楼层 |阅读模式
2威望
本帖最后由 无尾壁虎 于 2019-11-15 18:31 编辑

执行以下代码到第二次 render() 的时候,出现 segmentation fault (core dumped) 错误,不知什么原因,求大神解决
import sys
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import QApplication
def render(source_html):
    class Render(QWebEngineView):
        def __init__(self, html):
            self.html = None
            self.app = QApplication(sys.argv)
            QWebEngineView.__init__(self)
            self.loadFinished.connect(self._loadFinished)
            self.setHtml(html)
            self.app.exec_()
        def _callable(self, data):
            self.html = data
            self.app.quit()
        def _loadFinished(self, result):
            # 复制网页内容
            self.page().toPlainText(self._callable)
    return Render(source_html).html
if __name__ == "__main__":
    # 测试
    import requests
    url = "https://www.baidu.com"
    r = requests.get(url)
    r.encoding = "utf-8"
    source_html = r.text
    print(1, "-" * 20)
    print(render(source_html))
    print(2, "-" * 20)
    print(render(source_html))
    print(3, "-" * 20)
终端输出:
1 --------------------
qt5ct: using qt5ct plugin
QFileSystemWatcher::removePaths: list is empty
QFileSystemWatcher::removePaths: list is empty
新闻
hao123
地图
视频
贴吧
登录
更多产品

关于百度 About Baidu

©2017 Baidu 使用百度前必读  意见反馈 京ICP证030173号  
2 --------------------
qt5ct: using qt5ct plugin
[1]    25746 segmentation fault (core dumped)  python test_100_html2txt_by_pyqt5.py

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表