Reputation: 71
Similar to Download images from website
I'd like to download a list of images from a website where the url is having -number at the end. I was thinking of a simple loop that counts up like
#!/bin/bash
baseurl=https://www.theguardian.com/global-development-professionals-network/gallery/2016/dec/23/prayer-around-the-world-in-pictures-religion#img-
for (( c=1; c<=5; c++ ))
do
wget $baseurl-$c
done
But how can I break out of the loop when there is no valid picture any more?
Upvotes: 3
Views: 104
Reputation: 71
@Baurin Leza
your answer pointed me in the right direction. The following script works as expected:
#!/bin/bash
baseurl=http://www.novomestskykuryr.info/01-sada-02/fotogalerie-94/slides/img
for (( c=100; c<=200; c++ ))
do
wget $baseurl-$c.jpg || break
done
Upvotes: 2
Reputation: 2104
you can use || for do another command if wget $baseurl-$c fail, like this:
wget $baseurl-$c || echo "Some log to log file" > ./my_log.log
Upvotes: 3