为什么我不能用python从谷歌下载图片?

Sai*_*das 13 python python-3.x google-image-search

代码帮助我从谷歌下载了一堆图片。几天前它曾经可以工作,现在突然代码中断了。

代码 :

# 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()
Run Code Online (Sandbox Code Playgroud)

输出日志:

项目编号:1 --> 项目名称 = Apple 正在评估...开始下载...

不幸的是,由于某些图像无法下载,因此无法下载所有 4 个。0 是我们为这个搜索过滤器得到的全部!

错误:0

项目编号:1 --> 项目名称 = 橙色 正在评估...开始下载...

不幸的是,由于某些图像无法下载,因此无法下载所有 4 个。0 是我们为这个搜索过滤器得到的全部!

错误:0

项目编号:1 --> 项目名称 = 葡萄 正在评估...开始下载...

不幸的是,由于某些图像无法下载,因此无法下载所有 4 个。0 是我们为这个搜索过滤器得到的全部!

错误:0

项目编号:1 --> 项目名称 = 西瓜 正在评估...开始下载...

不幸的是,由于某些图像无法下载,因此无法下载所有 4 个。0 是我们为这个搜索过滤器得到的全部!

错误:0

这实际上创建了一个文件夹,但其中没有图像。

fun*_*man 2

确实这个问题出现不久,Github 上已经有一堆类似的问题:

不幸的是,没有官方的解决方案,目前,您可以使用讨论中提供的临时解决方案。