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 http://www.imagebam.com/gallery/hwtfu6m7es3gun1emmpy2uheohrcckmt/

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?

  • I think it's more of a Superuser.com or StackOverflow.com question.
    – gertvdijk
    Dec 23, 2012 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, 2012 at 1:30
  • 1
    Adding a -l1 switch will restrict wget to downloading only the page and its immediate links. Dec 24, 2012 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 http://www.imagebam.com/gallery/hwtfu6m7es3gun1emmpy2uheohrcckmt/
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

You must log in to answer this question.

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