PyQt5 v5.6 QWebEngineView ile HTML'yi nasıl "işleyebilirim"?PyQt5'in QWebEngineView'iyle HTML nasıl oluşturulur
Daha önce bu görevi PyQt5 v5.4.1 QWebPage ile gerçekleştirdim, ancak daha yeni QWebEngineView'i denemek için suggested oldu.
İşte o uygulama var (genellikle beklendiği gibi çalışır, ancak bazı siteler ve durumlar için süresiz asmak için bir eğilimi var): Aşağıda QWebEngineView kullanarak benim girişimi
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(render(sample_html))
olduğunu. Ubuntu üzerinde Birincisi, kurulum ve PyQt5 v5.6 kurulumu: Python ... parçalama arızası aşağıdaki sonuçlar için Şimdi
# install PyQt5 v5.6 wheel from PyPI
pip3 install --user pyqt5
# link missing resources
ln -s ../resources/icudtl.dat ../resources/qtwebengine_resources.pak ../resources/qtwebengine_resources_100p.pak ../resources/qtwebengine_resources_200p.pak ../translations/qtwebengine_locales ~/.local/lib/python3.5/site-packages/PyQt5/Qt/libexec/
:
def render(source_html):
"""Fully render HTML, JavaScript and all."""
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
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 _loadFinished(self, result):
# what's going on here? how can I get the HTML from toHtml?
self.page().toHtml(self.callable)
self.app.quit()
def callable(self, data):
self.html = data
return Render(source_html).html
import requests
sample_html = requests.get(dummy_url).text
print(render(sample_html))
sorun asenkron çağrısına yalan görünüyor toHtml()
. Oldukça basit olması gerekiyormuş gibi görünüyor, ama onunla ne yapacağım konusunda bir kayıp yapıyorum. C++ bağlamında discussed olduğunu görüyorum, fakat bunu Python'a nasıl çevireceğimi bilmiyorum. HTML'yi nasıl alabilirim? konu üzerine tartışma