Quantcast
Channel: Preguntas activas con las etiquetas pyqt - Stack Overflow en español
Viewing all articles
Browse latest Browse all 77

Redimencionar dinámicamente pantalla web de QWebEngineView PyQt5 - Python

$
0
0

Hago captura de pantalla de completa un navegador con PyQt5, con el widget QWebEngineView, el inconveniente que tengo es; las páginas cuando cargan tienen distintas alturas, la cual me dificulta calcular tu altura real antes de capturar. Por ahora le pongo dimensiones estáticas al iniciarlizar el script size = (1050,8000), con esta medida algunas urls salen con un espacio en blanco en la parte inferior o a algunos no entra todo el contenido de la web. Lo que realmente quisiera es tomar la altura real de lo que se ha renderizado la pagina al terminar de cargar el html y capturar la pantalla completa. ¿Cómo puedo redimencionar dinámicanente en tiempo de ejecuación y recien capturar?, Gracias.

Esto es mi código completo:

from os.path import basenamefrom os.path import dirnamefrom os.path import joinimport sysfrom PyQt5.QtCore import Qtfrom PyQt5.QtCore import QUrlfrom PyQt5.QtCore import QTimerfrom PyQt5.QtGui import QPixmapfrom PyQt5.QtWebEngineWidgets import QWebEngineViewfrom PyQt5.QtWidgets import QApplicationdef finished(browser, url, wait_ms):    def inner(result):        if result and browser.url().toString() == url:            # fname = join(dirname(__file__), basename(url) +".png")            fname = "hola.png"            QTimer.singleShot(wait_ms, lambda: capture(browser, fname))    return innerdef capture(browser, fname):    size = browser.contentsRect()    print ('img zise===>',size)    img = QPixmap(size.width(), size.height())    browser.render(img)    img.save(fname)    browser.close()url = 'https://eltiempo.pe/bono-alimentario-2022-link-beneficiarios-como-consultar-y-quienes-lo-cobraran-lr/'size = (1050,8000)app = QApplication(sys.argv)browser = QWebEngineView()browser.setAttribute(Qt.WA_DontShowOnScreen, True)browser.setAttribute(Qt.WA_DeleteOnClose, True)# size = browser.page().contentsSize().toSize()print ('SIZE===>', size, )browser.resize(*size)# browser.setZoomFactor(0)browser.show()browser.load(QUrl(url))print ('A visitado.... ...', url)browser.loadFinished.connect(finished(browser, url, 3000))sys.exit(app.exec_())

Viewing all articles
Browse latest Browse all 77

Trending Articles