-1

What I am trying to do is download a file from a url like this: http://www.example.com/down/files/425/document-preview?

When I visit this url in my browser, it triggers a file called for example: 425.doc this can be a pdf, rtf, txt, docx etc. file format.

wget is currently saving this file as: document-preview? is there anyway to save it as the file download that is triggered by the url?

This is what I am doing so far:

wget --save-cookies cookies.txt --post-data 'js_username=example@example.com&js_password=123456789' --keep-session-cookies parameter -p http://www.test.co.za/test/login

wget --load-cookies cookies.txt -p www.test.co.za/downloads/doc/425399/doc-preview? --keep-session-cookies

I want to change the values in a loop of the 425399 for example: from 425399 to 525399 it logs in perfectly and downloads, just want to capture filename and save it as that filename instead of doc-preview? which does not save the right file name which should be: 425399.doc

I did get this example online to do the batch download: wget www.whatever.com/folder/{1..30}.html

but my problem is the file name

louis_coetzee
  • 139
  • 1
  • 4
  • Probably off-topic for SF, on-topic at SuperUser, but already asked and answered here - http://superuser.com/questions/301044/how-to-wget-a-file-with-correct-name-when-redirected – EightBitTony Jun 11 '12 at 23:06
  • Thanks for your help, that was the correct answer. Sorry for posing in the wrong place. – louis_coetzee Jun 11 '12 at 23:13

2 Answers2

1

use -O option will save files as the specified name

for i in {425399..525399}
do
        wget -O $i.doc --load-cookies cookies.txt -p www.test.co.za/downloads/doc/$i/doc-preview? --keep-session-cookies
done
ray
  • 471
  • 3
  • 3
0

The complete solution to the problem as stated above.

wget --save-cookies cookies.txt --post-data 'email_address=example@example.com&password=1234' --keep-session-cookies http://www.example.com/login.php

wget --load-cookies cookies.txt -p http://www.example.com/download.php?file_id=file_{1..5000} --content-disposition --directory-prefix=downloads
jscott
  • 24,484
  • 8
  • 79
  • 100
louis_coetzee
  • 139
  • 1
  • 4