paper100
paper100

Reputation: 21

Using cURL with two matching ranges

I am trying to download a batch of images using cURL. The images are all saved in separate directories, named the same as the image filenames.

I tired using the square brackets to set two range's, one for the filename and one for the directory but that didn't work due to the command going through the first range and then the second range, rather than both ranges going up by 1 at the same time.

curl -f "https://example.com/images/products/[100-200]/[100-200].jpg" -o "/Users/user/Desktop/output/#1.jpg"

Is it possible to set the cURL command so that both directory and file name numbers go up by 1 each time?

Example:

https://example.com/images/products/100/100.jpg
https://example.com/images/products/101/101.jpg
https://example.com/images/products/102/102.jpg
https://example.com/images/products/103/103.jpg

ect...

Upvotes: 2

Views: 333

Answers (1)

moebius
moebius

Reputation: 2269

As far as I know, that can't be done with curl url globbing. You could use your existing code to download everything, and then delete the unwanted files, but that would be inefficient.

Your best bet might be to use a loop:

for index in {100..200}; do 
  curl -f "https://example.com/images/products/$index/$index.jpg" -o "/Users/user/Desktop/output/$index.jpg"
done

Upvotes: 2

Related Questions