Javascript 通过控制台使用jQuery一次性下载mp4文件

Javascript 通过控制台使用jQuery一次性下载mp4文件,javascript,jquery,download,media,Javascript,Jquery,Download,Media,我正在一个新窗口中打开HTML页面。这些页面有一个媒体文件“.mp4”和其他标记。我可以通过以下代码保存页面: 如何仅下载打开的每个HTML页面内的媒体? 有没有办法找到并保存这些页面加载的任何媒体? var-anchor=document.getElementsByTagName('a'); 对于(变量i=0;iresp.blob()) .然后(blob=>{ constURL=window.url.createObjectURL(blob); 常量a=document.createEleme

我正在一个新窗口中打开HTML页面。这些页面有一个媒体文件
“.mp4”
和其他标记。我可以通过以下代码保存页面:

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

var-anchor=document.getElementsByTagName('a');
对于(变量i=0;iresp.blob())
.然后(blob=>{
constURL=window.url.createObjectURL(blob);
常量a=document.createElement('a');
a、 style.display='none';
a、 href=url;
a、 setAttribute('target','u blank');
a、 download=anchor[i].innerText;//文件名
文件.正文.附件(a);
a、 单击();
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);
});
};

添加一个
a.setAttribute(“target”,_blank”)a.setAttribute(“下载”,“文件名”+i+'.mp4')
。。如果没有测试,我不确定直接设置
a.download
是否有效。我刚刚更新了问题。谢谢
    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);
});
};