Download full web page
-
wrote on 31 Aug 2022, 17:27 last edited by
Hi guys, it's possible to download a full web page with the QtWebEngine (Python3)?
-
@JonB Can I use it with PyQT5? What I'm doing wrong?
try: self.wvTest.page().save( # Working (output of indexed image) filepath, format=QWebEngineDownloadItem.MimeHtmlSaveFormat # Not working # filepath, format=QWebEngineDownloadRequest.MimeHtmlSaveFormat )
wrote on 1 Sept 2022, 16:19 last edited by mpergand 9 Jan 2022, 16:21@Black-Cat
First you have to register to downloadRequested(QWebEngineDownloadItem *download) signal emitted by the default profile.Then in the slot method (sorry C++ code)
void downloadRequested(QWebEngineDownloadItem *download) { if(download->isSavePageDownload()) { download->setSavePageFormat(QWebEngineDownloadItem::CompleteHtmlSaveFormat); download->accept(); } }
This method is called on response to a right-click on "Save Page" in the context menu of the webview.
-
@Black-Cat said in Download full web page:
Hi guys, it's possible to download a full web page with the QtWebEngine (Python3)?
Sure, Qt WebEngine's purposes is to let you download and view webpages.
If you meant "download to disk", call the
toHtml()
function (see https://doc.qt.io/qtforpython/PySide6/QtWebEngineCore/QWebEnginePage.html#PySide6.QtWebEngineCore.PySide6.QtWebEngineCore.QWebEnginePage.toHtml ) this will give you the web page as a HTML document, but you'll need to download the assets (such as images) separately. -
@Black-Cat said in Download full web page:
Hi guys, it's possible to download a full web page with the QtWebEngine (Python3)?
Sure, Qt WebEngine's purposes is to let you download and view webpages.
If you meant "download to disk", call the
toHtml()
function (see https://doc.qt.io/qtforpython/PySide6/QtWebEngineCore/QWebEnginePage.html#PySide6.QtWebEngineCore.PySide6.QtWebEngineCore.QWebEnginePage.toHtml ) this will give you the web page as a HTML document, but you'll need to download the assets (such as images) separately. -
@JKSH
But it's possible to create the same signal of the button "Save Page"? Because this method will link directly the images with the source (without download the images)?
wrote on 1 Sept 2022, 13:56 last edited by@Black-Cat
If you look on @JKSH's page there is https://doc.qt.io/qtforpython/PySide6/QtWebEngineCore/QWebEnginePage.html#PySide6.QtWebEngineCore.PySide6.QtWebEngineCore.QWebEnginePage.saveThis is a short cut for the following actions:
Trigger the Save web action.
Accept the next download item and set the specified file path and save format.
-
@Black-Cat
If you look on @JKSH's page there is https://doc.qt.io/qtforpython/PySide6/QtWebEngineCore/QWebEnginePage.html#PySide6.QtWebEngineCore.PySide6.QtWebEngineCore.QWebEnginePage.saveThis is a short cut for the following actions:
Trigger the Save web action.
Accept the next download item and set the specified file path and save format.
wrote on 1 Sept 2022, 15:39 last edited by Black Cat 9 Jan 2022, 15:40@JonB Can I use it with PyQT5? What I'm doing wrong?
try: self.wvTest.page().save( # Working (output of indexed image) filepath, format=QWebEngineDownloadItem.MimeHtmlSaveFormat # Not working # filepath, format=QWebEngineDownloadRequest.MimeHtmlSaveFormat )
-
@JonB Can I use it with PyQT5? What I'm doing wrong?
try: self.wvTest.page().save( # Working (output of indexed image) filepath, format=QWebEngineDownloadItem.MimeHtmlSaveFormat # Not working # filepath, format=QWebEngineDownloadRequest.MimeHtmlSaveFormat )
wrote on 1 Sept 2022, 16:19 last edited by mpergand 9 Jan 2022, 16:21@Black-Cat
First you have to register to downloadRequested(QWebEngineDownloadItem *download) signal emitted by the default profile.Then in the slot method (sorry C++ code)
void downloadRequested(QWebEngineDownloadItem *download) { if(download->isSavePageDownload()) { download->setSavePageFormat(QWebEngineDownloadItem::CompleteHtmlSaveFormat); download->accept(); } }
This method is called on response to a right-click on "Save Page" in the context menu of the webview.
-
@Black-Cat
First you have to register to downloadRequested(QWebEngineDownloadItem *download) signal emitted by the default profile.Then in the slot method (sorry C++ code)
void downloadRequested(QWebEngineDownloadItem *download) { if(download->isSavePageDownload()) { download->setSavePageFormat(QWebEngineDownloadItem::CompleteHtmlSaveFormat); download->accept(); } }
This method is called on response to a right-click on "Save Page" in the context menu of the webview.
1/7