这段代码帮助我从谷歌下载了很多图片。它在几天前还可以使用,但是现在突然出问题了。
代码:
# 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 --> 项目名称 = 苹果 评估中... 开始下载...
抱歉,由于一些图像无法下载,所有4个图像都无法下载。对于此搜索过滤器,我们只得到了0!
错误:0
项目编号:1 --> 项目名称 = 橙子 评估中... 开始下载...
抱歉,由于一些图像无法下载,所有4个图像都无法下载。对于此搜索过滤器,我们只得到了0!
错误:0
项目编号:1 --> 项目名称 = 葡萄 评估中... 开始下载...
抱歉,由于一些图像无法下载,所有4个图像都无法下载。对于此搜索过滤器,我们只得到了0!
错误:0
项目编号:1 --> 项目名称 = 西瓜 评估中... 开始下载...
抱歉,由于一些图像无法下载,所有4个图像都无法下载。对于此搜索过滤器,我们只得到了0!
错误:0
实际上创建了一个文件夹,但其中没有图像。