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

标签 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()

输出日志:

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



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

最佳答案

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

  • 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

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

    关于python - 为什么我不能用python从谷歌下载图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60134947/

    相关文章:

    Python 列表理解技巧

    python - 提取后视频帧是颠倒的

    python - 将 .txt 中的行读取到批处理文件中并作为参数传递到命令行?

    python - 删除组合框项目的按钮

    google-image-search - Google Image Search - 是否有以 XML 格式返回数据的 API?

    html - 谷歌从自己的网页上通过图像搜索

    python - 按多个单词的标签拆分的术语

    python - 如何使用正则表达式查找匹配词?

    python - 使用superclass .__ init()__而不是superclass()调用父类(super class)构造函数的原因

    microformats - 如何在 Google 图片中为我网站上的图片设置许可?