gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:27:15 26 4
gpt4 key购买 nike

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

代码:

# 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/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com