Skip to content

Instantly share code, notes, and snippets.

@luckyshot
Created September 18, 2020 13:28
Show Gist options
  • Save luckyshot/ac825647bcccbf3757c0834081e61304 to your computer and use it in GitHub Desktop.
Save luckyshot/ac825647bcccbf3757c0834081e61304 to your computer and use it in GitHub Desktop.
Download all images from website (JS + PHP)
var buffer = [];
document.querySelectorAll('img').forEach(function(item) {
if (item.src){
buffer.push( item.src );
}
});
console.log('Total items:', buffer.length );
localStorage.buffer = JSON.stringify(buffer);
// Now grab localStorage.buffer and paste it in PHP
<?php
$items = '[]'; // JSON string
$items = json_decode($items, true);
foreach($items as $item){
$filename = explode('/', $item);
$filename = $filename[ count($filename)-1 ];
if ( !file_exists('./downloads/'.$filename) ){
file_put_contents('./downloads/'.$filename, file_get_contents($item));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment