user7735544
user7735544

Reputation:

how to download files using pyqt5 webenginewidgets

I am learning pyqt5 and built a simple webbrowser in pyqt5 webengine . Now out of curiosity I want to know that is there a method by which I am able to download files using this minimalistic browser,Thanks in advance.

import sys
from PyQt5 import QtWidgets,QtGui,QtCore
from PyQt5.QtWebEngineWidgets import *
app=QtWidgets.QApplication(sys.argv)
w=QWebEngineView()
w.page().fullScreenRequested.connect(QWebEngineFullScreenRequest.accept)
w.load(QtCore.QUrl('https://google.com'))
w.showMaximized()
app.exec_()

Upvotes: 1

Views: 2545

Answers (1)

shao.lo
shao.lo

Reputation: 4636

The simplest possible way to download would be something like this...

def _downloadRequested(item): # QWebEngineDownloadItem
    print('downloading to', item.path())
    item.accept()

w.page().profile().downloadRequested.connect(_downloadRequested)

Upvotes: 3

Related Questions