In QWebEngineView by default the downloads are not handled, to enable it you have to use the downloadRequested signal of QWebEngineProfile, this transports a QWebEngineDownloadItem that you have to accept if you want the download to start:
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
class Widget(QtWidgets.QWidget):
def __init__(self, parent=None):
super(Widget, self).__init__(parent)
self.view = QtWebEngineWidgets.QWebEngineView()
self.view.page().profile().downloadRequested.connect(
self.on_downloadRequested
)
url = "https://domain/your.csv"
self.view.load(QtCore.QUrl(url))
hbox = QtWidgets.QHBoxLayout(self)
hbox.addWidget(self.view)
@QtCore.pyqtSlot("QWebEngineDownloadItem*")
def on_downloadRequested(self, download):
old_path = download.url().path() # download.path()
suffix = QtCore.QFileInfo(old_path).suffix()
path, _ = QtWidgets.QFileDialog.getSaveFileName(
self, "Save File", old_path, "*." + suffix
)
if path:
download.setPath(path)
download.accept()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
If you want to make a direct download you can use the download method of QWebEnginePage:
self.view.page().download(QtCore.QUrl("https://domain/your.csv"))
Update:
@QtCore.pyqtSlot("QWebEngineDownloadItem*")
def on_downloadRequested(self, download):
old_path = download.url().path() # download.path()
suffix = QtCore.QFileInfo(old_path).suffix()
path, _ = QtWidgets.QFileDialog.getSaveFileName(
self, "Save File", old_path, "*." + suffix
)
if path:
download.setPath(path)
download.accept()
download.finished.connect(self.foo)
def foo(self):
print("finished")