Download a list of files and use domain name as filename

1

I got a bunch of files to download which works great with

wget -i list_of_urls

but my problem is, that wget uses the filename of the downloaded file. Is there a way (or a different tool) which is able to use the whole url als filename, f.e.

http://www.example.com/file1.html
http://www.example.com/file2.html

Lead to the files:

http___www_example_com_file_1.html
http___www_example_com_file_2.html  

PascalTurbo

Posted 2015-09-06T14:46:38.290

Reputation: 356

Answers

1

Use some simple bash scripting. For example, if you have a file "foo" with the URLs:

http://www.google.com/index.html
http://www.cnn.com/index.html

You can run:

for i in `cat foo`; do wget $i -O `echo $i | sed 's/[^A-Za-z0-9]/_/g' | sed 's/_html$/.html/'`; done

which produces

http___www_cnn_com_index.html
http___www_google_com_index.html

patrickmdnet

Posted 2015-09-06T14:46:38.290

Reputation: 197

1Works like a charm. – Karimi – 2016-11-11T05:41:41.380

@Karimi Feel free to upvote the question and answer! – patrickmdnet – 2016-11-12T17:32:59.300

0

Use the "-x" option documented here. For example, given a file "foo" with contents:

http://www.google.com/index.html
http://www.cnn.com/index.html

If you run

wget -x -i foo

then you will get these files:

www.google.com/index.html
www.cnn.com/index.html

patrickmdnet

Posted 2015-09-06T14:46:38.290

Reputation: 197

That's nice but I really need a single file with the full name – PascalTurbo – 2015-09-06T15:13:07.917