Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I'm trying to download all the images from a certain ImageBam gallery. I tried doing this:

wget -P pics -H -nd -r -A '.jpg,.jpeg,.png,.gif,' -erobots=off

But it downloaded the whole website; all I need is the content from a certain <div> which includes thumbnails and original images. Is it possible to create a script to download content from one <div> and not the whole website?

share|improve this question
I think it's more of a or question. – gertvdijk Dec 23 '12 at 23:14
I don't think there is a way to download a portion of a page, you could download the whole page and then programmatically use grep/awk/sed/perl to parse out everything minus the part you want. Note there are HTML parsers available in most languages that can help tease out pieces of a HTML page as well. – slm Dec 24 '12 at 1:30
Adding a -l1 switch will restrict wget to downloading only the page and its immediate links. – Deer Hunter Dec 24 '12 at 3:00

1 Answer 1

The problem is difficult because the full pictures are not under the parent's tree, so it's hard to distinguish those paths from any others on the site. Also, the links to the full pictures are actually links to pages, in which the full resolution picture is embedded. There may be a more elegant solution, but here's one way to do it that works.

wget -np
grep HTML-Code index.html > html_code
grep -E -o 'http://thumbnails[^"]+' html_code > thumb_urls
grep -E -o 'http://www[^"]+' html_code > image_pages
wget -i thumb_urls
wget -P image_pages_dir -i image_pages
for file in image_pages_dir/*
    echo $file
    grep -m 1 -o -E 'http://.*jpg' $file >> full_image_urls
wget -i full_image_urls
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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