直接下载页面中的所有图片
$$('img').forEach(async (img) => {
try {
const fetchResponse = await fetch(img.src);
const blob = await fetchResponse.blob();
const a = document.createElement('a');
a.setAttribute('href', URL.createObjectURL(blob));
a.setAttribute('download', name);
a.click();
} catch (e) {}
});
在控制台中下载图片文件,一般网站都是预览图,点进去才是高清图,可以基于下面的进行修改
$$('img').forEach(async (img) => {
try {
let srcArr = img.src.split('/')
let name = srcArr.pop().split('?')[0]
const resolution = [960, 720, 640];
resolution.forEach((item) => {
name = name.replace(`${item}.`, '1280.');
});
const src = srcArr.concat([name]).join('/')
const fetchResponse = await fetch(src);
const blob = await fetchResponse.blob();
const a = document.createElement('a');
a.setAttribute('href', URL.createObjectURL(blob));
a.setAttribute('download', name);
a.click();
} catch (e) {}
});