如何使用PyQt5 v5.6qwebengineview“呈现”HTML?
我以前用PyQt5 v5.4.1qwebpage执行过这个任务,但是尝试新的QWebEngineView是suggested。
以下是实现(它通常按预期工作,但对于某些站点和情况有无限期挂起的趋势):def render(source_html):
"""Fully render HTML, JavaScript and all."""
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebKitWidgets import QWebPage
class Render(QWebPage):
def __init__(self, html):
self.html = None
self.app = QApplication(sys.argv)
QWebPage.__init__(self)
self.loadFinished.connect(self._loadFinished)
self.mainFrame().setHtml(html)
self.app.exec_()
def _loadFinished(self, result):
self.html = self.mainFrame().toHtml()
self.app.quit()
return Render(source_html).html
import requests
sample_html = requests.get(dummy_url).text
print(re