post

Using Python to Grab Images From a Web Site

I recently started a contest for a logo design (The link is not to my contest, just an example). Soon I had over 60 entries and I needed an easy way to present these logos to the client in a Power Point presentation. It takes two clicks to get to each image… no good. Thus the following script was created. It should serve as a good tutorial on how to use Python to do some basic web interactions.

#!/usr/bin/python
import urllib
import re

# Change the variables "contest" and "path"
def retrieveImage( contest, path, name ):
    url = "http://99designs.com/contests/" + contest + "/entries/" + name
    urllib.urlretrieve( url, path + name )

if __name__ == '__main__':
    contest = "6999" #The 99designs content number from which you want to extract images
    path = "../tmp/" #The path where you want to store the downloaded images
    url = urllib.urlopen( "http://99designs.com/contests/" + contest + "/feed" )
    url_string = url.read()
    p = re.compile( 'd*.large.w{3,3}' )
    iterator = p.finditer( url_string )
       for match in iterator:
           retrieveImage( contest, path , match.group() )

Speak Your Mind

*