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
我来回答