DEV Community

Cover image for Scraping images for batch downloads

Scraping images for batch downloads

Hey, I'm Lydia. I like words and information! Yup, both those things are pretty great. I'm a designer turned software engineer.
・1 min read

To use existing image APIs, like LoremFlickr or PlaceImg, you can run this for loop directly in your terminal:

#install wget if you don't already have it
brew install wget 

for i in {1..10} ; do wget -O dog-"$i".jpg
Enter fullscreen mode Exit fullscreen mode

This will go to the url 10 times, and download the request response as a jpg image, renaming the file "dog" with the "index number" appended. (ie. dog1.jpg, dog2.jpg, etc.)

Here's another resource by a
loadenmb for bulk downloads using your shell.

To scrape a whole page, you can go through Google DevTools to get a list of all image urls. I'm sure there are other ways to go about this, but this is the way I found. It was also quite fun to get more familiarized with the DevTools Network panel and filtering capabilities through it.

-Open dev tools
-Select the Network panel
-Click the funnel icon to enable filtering
-Select Img to enable filter for images only
-Click and highlight all the image urls you want
-Copy urls into a text file

If your txt file is formatted correctly(with a new url on each line), with wget you can run this code to download all the urls from that txt file. FYI you may need to convert those downloads into JPEGs afterwards, something that I ended up just doing through my Mac Finder.

wget -i yourtextfile.txt
Enter fullscreen mode Exit fullscreen mode

Hopefully these tips can help someone out there :D Best of luck with your scraping!

Discussion (0)

Forem Open with the Forem app