Pobieranie grafiki ze strony za pomocą js i HAR
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js';
document.head.appendChild(script);
// Wklej JSON HAR jako obiekt
const har = TU_WKLEJ_HAR ;
const urls = har.log.entries
.filter(e => e.response?.content?.mimeType?.startsWith('image/'))
.map(e => e.request.url);
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
(async () => {
const zip = new JSZip();
for (let i = 0; i < urls.length; i++) {
try {
const res = await fetch(urls[i]);
const blob = await res.blob();
const ext = blob.type.split('/')[1] || 'jpg';
zip.file(`image_${i}.${ext}`, blob);
const delay = Math.floor(Math.random() * 5000) + 1000;
console.log(`Dodano ${i+1}/${urls.length}, czekam ${delay} ms`);
await sleep(delay);
} catch (err) {
console.error('Błąd przy pobieraniu', urls[i], err);
}
}
console.log('Generowanie ZIP...');
const content = await zip.generateAsync({ type: 'blob' });
// Tworzymy widoczny link do pobrania
const a = document.createElement('a');
a.href = URL.createObjectURL(content);
a.download = 'obrazy.zip';
a.textContent = 'Kliknij tutaj, aby pobrać ZIP z obrazami';
a.style.display = 'block';
a.style.fontSize = '18px';
a.style.margin = '20px 0';
a.style.color = 'blue';
a.style.cursor = 'pointer';
document.body.appendChild(a);
console.log('Pobieranie zakończone. Kliknij link na stronie, aby zapisać ZIP.');
})();
Gdzie znajdę HAR.
