Created
September 18, 2020 13:28
-
-
Save luckyshot/ac825647bcccbf3757c0834081e61304 to your computer and use it in GitHub Desktop.
Download all images from website (JS + PHP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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