5

I want to download all the images from an URL using wget and set the name of output file based on the url.

For example, if I download this picture:

wget https://www.electrictoolbox.com/images/icons/linux-bsd.gif

The filename will be linux-bsd.gif but I want it to be images_icons_linux-bsd.gif

I would like it to be automated.

How can I achieve this?

2 Answers 2

6

How about:

wget --output-document=images_icons_linux-bsd.gif https://www.electrictoolbox.com/images/icons/linux-bsd.gif

...all in one line.

3

Finding all images of a website

As explained here, you can do so with the following:

# get all pages
curl 'http://domain.com/id/[1-151468]' -o '#1.html'

# get all images
grep -oh 'http://pics.domain.com/pics/original/.*jpg' *.html >urls.txt

# download all images
sort -u urls.txt | wget -i-

Getting the Image

Here's a bash script, taking a URL as the first parameter:

#!/bin/bash
name=`echo $1 | sed 's/\//_/g' | sed 's/https:__[a-z\.]\+_//g'`
wget -O $name $1 

It may not work with some URLs, just so you know.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .