通过控制台通过jQuery一次下载mp4文件

问题描述

我正在新窗口中打开HTML页面。这些页面除其他标签外还具有媒体文件".mp4"。我可以通过以下代码保存页面:

如何仅下载每个打开的HTML页面内部的媒体? 有没有办法找到并保存这些页面加载的任何媒体?

var anchor = document.getElementsByTagName('a');
for (var i=0; i < anchor.length; i++){

    fetch(anchor[i].href)
        .then(resp => resp.blob())
        .then(blob => {
            const url = window.URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.style.display = 'none';
            a.href = url;
            a.setAttribute('target','_blank');
            a.download = anchor[i].innerText; // the file name
            document.body.appendChild(a);
            a.click();
            window.URL.revokeObjectURL(url);
        });
}

解决方法

试试这个:

    var a = document.getElementsByTagName("video");
for(i of a){
console.log(i.src);
fetch(i.src)
.then(resp => resp.blob())
.then(blob => {
    const url = window.URL.createObjectURL(blob);
    const b = document.createElement('a');
    b.style.display = 'none';
    b.href = url;
    b.setAttribute("download",'arquivo.mp4')
    b.download = 'arquivo.mp4'; // the file name
    document.body.appendChild(b);
    b.click();
    window.URL.revokeObjectURL(url);
});
};

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...