【发布时间】:2020-02-09 08:56:31
【问题描述】:
代码帮助我从谷歌下载了一堆图片。几天前它曾经工作过,现在突然代码中断了。
代码:
# 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()
输出日志:
项目编号:1 --> 项目名称 = Apple Evaluating...开始下载...
很遗憾,所有 4 个都无法下载,因为有些图像 不可下载。 0 是我们为这个搜索过滤器得到的全部!
错误:0
Item no.: 1 --> Item name = Orange Evaluating...开始下载...
很遗憾,所有 4 个都无法下载,因为有些图像 不可下载。 0 是我们为这个搜索过滤器得到的全部!
错误:0
Item no.: 1 --> Item name = Grapes Evaluating...开始下载...
很遗憾,所有 4 个都无法下载,因为有些图像 不可下载。 0 是我们为这个搜索过滤器得到的全部!
错误:0
商品编号:1 --> 商品名称 = 西瓜 评估中...开始 下载...
很遗憾,所有 4 个都无法下载,因为有些图像 不可下载。 0 是我们为这个搜索过滤器得到的全部!
错误:0
这实际上创建了一个文件夹,但其中没有图像。
【问题讨论】:
-
我不明白为什么这篇文章有 2 个不喜欢?
-
我也有同样的问题。几天前它工作正常。
标签: python python-3.x google-image-search