'**SUMMARY**
This function downloads images from Google Image search based
on the tag you provide. The number is the number of images you
want to have in the list. Valid values for size are \'thumb\', \'small\',
\'medium\', \'large\' or a tuple of exact dimensions i.e. (640,480).
Note that \'thumb\' is exceptionally faster than others.
.. Warning::
This requires the python library Beautiful Soup to be installed
http://www.crummy.com/software/BeautifulSoup/
**PARAMETERS**
* *tag* - A string of tag values you would like to download.
* *number* - An integer of the number of images to try and download.
* *size* - the size of the images to download. Valid options a tuple
of the exact size or a string of the following approximate sizes:
* thumb ~ less than 128x128
* small  ~ approximately less than 640x480 but larger than 128x128
* medium ~  approximately less than 1024x768 but larger than 640x480.
* large ~ > 1024x768
**RETURNS**
Nothing - but caches local copy of images.
**EXAMPLE**
>>> imgs = ImageSet()
>>> imgs.download("ninjas")
>>> imgs.show(ninjas)'

def download(self, tag=None, number=10, size='thumb'):

    try:
        from BeautifulSoup import BeautifulSoup
    except:
        print 'You    need    to    install    Beatutiul    Soup    to    use    this    function'
        print 'to    install    you    can    use:'
        print 'easy_install    beautifulsoup'
        return
    INVALID_SIZE_MSG = "I    don't    understand    what    size    images    you    want.\n        Valid    options:    'thumb',    'small',    'medium',    'large'\n            or    a    tuple    of    exact    dimensions    i.e.    (640,480)."
    if isinstance(size, basestring):
        size = size.lower()
        if (size == 'thumb'):
            size_param = ''
        elif (size == 'small'):
            size_param = '&tbs=isz:s'
        elif (size == 'medium'):
            size_param = '&tbs=isz:m'
        elif (size == 'large'):
            size_param = '&tbs=isz:l'
        else:
            print INVALID_SIZE_MSG
            return None
    elif (type(size) == tuple):
        (width, height) = size
        size_param = ((('&tbs=isz:ex,iszw:' + str(width)) + ',iszh:') + str(height))
    else:
        print INVALID_SIZE_MSG
        return None
    imgurl_re = re.compile('(?<=(&|\\?)imgurl=)[^&]*((?=&)|$)')
    add_set = ImageSet()
    candidate_count = 0
    while (len(add_set) < number):
        opener = urllib2.build_opener()
        opener.addheaders = [('User-agent', 'Mozilla/5.0')]
        url = (((('http://www.google.com/search?tbm=isch&q=' + urllib2.quote(tag)) + size_param) + '&start=') + str(candidate_count))
        page = opener.open(url)
        soup = BeautifulSoup(page)
        img_urls = []
        if (size == 'thumb'):
            imgs = soup.findAll('img')
            for img in imgs:
                dl_url = str(dict(img.attrs)['src'])
                img_urls.append(dl_url)
        else:
            for link_tag in soup.findAll('a', {'href': re.compile('imgurl=')}):
                dirty_url = link_tag.get('href')
                dl_url = str(re.search(imgurl_re, dirty_url).group())
                img_urls.append(dl_url)
        for dl_url in img_urls:
            try:
                add_img = Image(dl_url, verbose=False)
                if ((add_img.height != 0) and (add_img.width != 0)):
                    add_set.append(add_img)
            except:
                None
            if (len(add_set) >= number):
                break
    self.extend(add_set)
