Здесь я создаю класс:
Код: Выделить всё
class DownloadManagerWidget(QWidget):
def downloadRequested(self, download: QWebEngineDownloadRequest):
assert download and download.state() == QWebEngineDownloadRequest.DownloadRequested
# Prompt the user for a file name
path, _ = QFileDialog.getSaveFileName(self, "Save as", QDir(download.downloadDirectory()).filePath(download.downloadFileName()))
if path.isEmpty():
return
# Set download directory and file name
download.setDownloadDirectory(QFileInfo(path).path())
download.setDownloadFileName(QFileInfo(path).fileName())
download.accept()
# Add the download to the download manager
self.add(DownloadWidget(download))
# Show the download manager
self.show()
Код: Выделить всё
self.download_manager_widget = DownloadManagerWidget()
self.download_manager_widget.setAttribute(Qt.WidgetAttribute.WA_QuitOnClose, False)
QWebEngineProfile.defaultProfile().downloadRequested.connect(self.download_manager_widget.downloadRequested)
Код: Выделить всё
js: Access to XMLHttpRequest at 'https://684d0d47.akstat.io/' from origin 'https://download.cnet.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Код: Выделить всё
Traceback (most recent call last): File "D:\mybrowser.py", line 14, in downloadRequested assert download and download.state() == QWebEngineDownloadRequest.DownloadRequested
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: type object 'QWebEngineDownloadRequest' has no attribute 'DownloadRequested'
Подробнее здесь: https://stackoverflow.com/questions/779 ... with-pyqt6