How to download images sequentially from a website using WGet?

2

I need to know where the error is in the command:

 wget http://shadowera.com/cards/se{001..200}.jpg

I used the site "shadowera" for testing. I need to know how to save multiple images at once, so it is not working.

    
asked by anonymous 25.04.2014 / 03:54

1 answer

5

Solution

Before using this loop, type cmd /v into the console to enable parameter expansion:

set i=1000 && for /l %a in (1,1,200) do (
   set /a "i=!i!+1" && wget http://shadowera.com/cards/se!i:~1,3!.jpg )

The line break is for easy reading only.

Explanation

Since we are using CMD, not a Shell, {001..200} expansion does not work. The solution found was for .

for /l %a in (1,1,200) do ( ...comandos... )

The initial problem is that the maximum that a for normal of the CMD would give us, would be a count of 1 to 200, not 001 to 200, which is the necessary output for the problem, since the files are se001.jpg to se200.jpg , not se1.jpg on.

So the simple solution would be to count from 1001 to 1200 and take the last three digits only. For this, the initial idea would be to use the CMD substrings:

%variavel:~posicaoinicial,final%

As nothing is simple, unfortunately CMD substrings only work for "conventional" environment variables, and do not apply to for, %a in case.

For this, we use an additional variable, i , starting with 1000, and increment it during the loop. To keep everything in one row, we use && (and) to concatenate commands.

set i=1000 && ..for.. ( set /a "i=%i%+1 ..

But ... This does not work!

It does not work, because the assignment of the sets is done first, and it will execute the following command with the wrong values.

The solution: start a CMD with flag /V , which activates the delayed expansion of the variable, which solves our problem. For this we use the format !variavel! instead of %variável%

The result is the compound command, from the beginning of the response.

    
25.04.2014 / 05:43