Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why couldn't I download images from google with python?

The code helped me download bunch of images from google. It used to work a few days back and now all of the sudden the code breaks.

Code :

# importing google_images_download module 
from google_images_download import google_images_download  

# creating object 
response = google_images_download.googleimagesdownload()  

search_queries = ['Apple', 'Orange', 'Grapes', 'water melon'] 


def downloadimages(query): 
    # keywords is the search query 
    # format is the image file format 
    # limit is the number of images to be downloaded 
    # print urs is to print the image file url 
    # size is the image size which can 
    # be specified manually ("large, medium, icon") 
    # aspect ratio denotes the height width ratio 
    # of images to download. ("tall, square, wide, panoramic") 
    arguments = {"keywords": query, 
                 "format": "jpg", 
                 "limit":4, 
                 "print_urls":True, 
                 "size": "medium", 
                 "aspect_ratio": "panoramic"} 
    try: 
        response.download(arguments) 

    # Handling File NotFound Error     
    except FileNotFoundError:  
        arguments = {"keywords": query, 
                     "format": "jpg", 
                     "limit":4, 
                     "print_urls":True,  
                     "size": "medium"} 

        # Providing arguments for the searched query 
        try: 
            # Downloading the photos based 
            # on the given arguments 
            response.download(arguments)  
        except: 
            pass

# Driver Code 
for query in search_queries: 
    downloadimages(query)  
    print()

Output log:

Item no.: 1 --> Item name = Apple Evaluating... Starting Download...

Unfortunately all 4 could not be downloaded because some images were not downloadable. 0 is all we got for this search filter!

Errors: 0

Item no.: 1 --> Item name = Orange Evaluating... Starting Download...

Unfortunately all 4 could not be downloaded because some images were not downloadable. 0 is all we got for this search filter!

Errors: 0

Item no.: 1 --> Item name = Grapes Evaluating... Starting Download...

Unfortunately all 4 could not be downloaded because some images were not downloadable. 0 is all we got for this search filter!

Errors: 0

Item no.: 1 --> Item name = water melon Evaluating... Starting Download...

Unfortunately all 4 could not be downloaded because some images were not downloadable. 0 is all we got for this search filter!

Errors: 0

This actually create a folder but no images in it.

like image 508
Sai Krishnadas Avatar asked Feb 09 '20 08:02

Sai Krishnadas


People also ask

How do you save an image in Python?

Saving an image in Python is just as simple. You simply call save() and pass in the name you want used to save your image. This method will save the image in the format identified by the extension on the filename you pass in.

Can Python generate images?

This article is a short overview of three ways to generate images with Python: Naive Bayes, GANs, and VAEs. Each uses the MNIST handwritten digit dataset. Images can be generated using Naive Bayes; no fancy neural network is required.


2 Answers

google_images_download project is no longer seems compatible wrt Google APIs.

As an alternative you can try simple_image_download.

like image 73
Kaustuv Avatar answered Oct 11 '22 05:10

Kaustuv


Indeed the issue has appeared not so long ago, there are already a bunch of similar Github issues:

  • https://github.com/hardikvasa/google-images-download/pull/298
  • https://github.com/hardikvasa/google-images-download/issues/301
  • https://github.com/hardikvasa/google-images-download/issues/302

Unfortunately, there is no official solution, for now, you could use the temporary solution that was provided in the discussions.

like image 2
funnydman Avatar answered Oct 11 '22 04:10

funnydman