2

Using Windows 10 and wget to download files from a specific location, installed and configured WSL2. Once the setup was done, opened and ran the following command

sudo apt-get install wget

Then, ran the following command

wget --header='Accept-Language: en-US,en;q=0.9,pt-PT;q=0.8,pt;q=0.7,de;q=0.6,fr;q=0.5,es;q=0.4,it;q=0.3,gl;q=0.2,hu;q=0.1' --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" -c "http://www.centrodeinformacao.ren.pt/_layouts/CI.GetExcel/SafeGetExcel.aspx?T=CRG&P="{1..3}"-"{1..12}"-"{2019,2020}"&variation=PT" -w 1

This saves the files in \\wsl$\Ubuntu-18.04\home\molecoder with the name SafeGetExcel.aspx?T=CRG&P=1-1-2020&variation=PT. If I want them as .xls, currently will need to go one by one and change the end of the file to .xls or automatically rename the file to what I want.

If I use

wget --header='Accept-Language: en-US,en;q=0.9,pt-PT;q=0.8,pt;q=0.7,de;q=0.6,fr;q=0.5,es;q=0.4,it;q=0.3,gl;q=0.2,hu;q=0.1' --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" -c "http://www.centrodeinformacao.ren.pt/_layouts/CI.GetExcel/SafeGetExcel.aspx?T=CRG&P="{1..3}"-"{1..12}"-"{2019,2020}"&variation=PT" -O {1..3}_{1..12}_{2019,2020}.xls -w 1

Then I'll get all the files with the name 1_1_2019.xls. How can I get that number to actually increase respectively (1_1_2019.xls, 1_1_2020.xls, 1_2_2019.xls, ...)?

2

(I think that the example in your post should have been 1_1_2019.xls, 1_2_2019.xls, 1_3_2019.xls, which is what I base my answer on.)

This is not possible using wget alone, except if you construct a bash-type script that loops on the files.

I suggest using instead the utility youtube-dl.

Youtube-dl supports the %(autonumber)s variable with calls such as:

youtube-dl -a URL-file -o '-o "%(autonumber)s-%(title)s.%(ext)s"

The starting number can be set by the parameter --autonumber-start NUMBER to specify the start value for %(autonumber)s, where the default is 1.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.