0

Is there a program/app for Ubuntu that allows to download several images from a page? To be exact, I want to get some pictures from the site

http://www.cookingforengineers.com/

Some of the recepies are an endless list of pics and I want to get them all together.

I tried DownThemAll with Firefox, but 1. I could only get the thumbnails and 2. I use Chrome now.

Carlos
  • 131
  • Well, if you want to uber-l33t about it, I could probably give you a Python/BASH script to run... :) – RPiAwesomeness Nov 14 '14 at 22:32
  • Thanks, @RPiAwesomeness The thing is that I am VERY new to Ubuntu and I do not know a thing about code or scripts... I am looking for the easy graphic UI where I just select by clicking or type the URL (something like Bulk Image Downloader in windows) – Carlos Nov 14 '14 at 22:41
  • I don't use Chrome but have you tried searching for any such extension in the Chrome Extensions Gallery? – Horizon Nov 14 '14 at 23:36

1 Answers1

3

Despite being unfamiliar with coding, this should still do what you want. Of course, you're more than welcome to wait for another user to post a GUI solution.

Simply copy and paste the following code into a text document and save it as dlimgs.py. I recommend making a new folder in your home directory called bin and saving it there.

#!/ust/bin/env python

import sys,urllib2,re

def main(url):
    page = getpage(url)
    start = page.find('articlebody')
    page = page[start:]
    lines = page.split('\n')
    for l in lines:
        if ('<img' in l) and ('.jpg' in l):
            matches = re.search(".*<img.*'(.*\.jpg)'.*",l)
            img = matches.group(1)
            name = img[img.rfind('/')+1:]
            print 'Downloading: '+name
            img = getpage(img)
            with open(name,'w') as f:
                f.write(img)

def getpage(url):
    user_agent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0'
    headers = {'User-Agent':user_agent}
    req = urllib2.Request(url, None, headers);
    response = urllib2.urlopen(req)
    return response.read()

if __name__ == '__main__':
    main(sys.argv[1])

Then open a terminal with Ctrl+Alt+T and do the following:

  1. Move to where you saved it using the cd command (Example: cd ~/bin)
  2. Invoke the script with python dlimgs.py <url>

It will download all the images and save them in the ~/bin folder. Note that this was written specifically for the website you supplied in the question, and so will skip the header images at the top of the page. It will probably throw errors for other websites. One more note, it will overwrite any images with the same filenames in the ~/bin dir so be careful.

TheSchwa
  • 3,820
  • Amazing! Upvoting... – Horizon Nov 14 '14 at 23:34
  • Thank you, @TheSchwa

    I have a doubt on the way to write the webpage...

    On the third and fourth lines, should http://www.cookingforengineers.com be inside the parentheses, or should I delete the parentheses?

    – Carlos Nov 28 '14 at 12:23
  • @CarlosC After saving the python script in a text file, this is an example of the command you would type on the command line: python dlimgs.py "http://www.cookingforengineers.com/recipe/55/Mini-Hamburgers". You do not have to edit the script; it reads the webpage url that you give from the command line. – TheSchwa Nov 28 '14 at 18:41