该代码帮助我从Google下载了一堆图像。它曾经工作了几天,现在突然间代码中断了。
代码:
# 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评估中...开始下载...
不幸的是,由于某些图像无法下载,因此无法全部下载4个图像。搜索过滤器仅获得0!
错误:0
编号:1->物品名称=橙色评估中...开始下载...
不幸的是,由于某些图像无法下载,因此无法全部下载4个图像。搜索过滤器仅获得0!
错误:0
产品编号:1->产品名称=葡萄评估中...开始下载...
不幸的是,由于某些图像无法下载,因此无法全部下载4个图像。搜索过滤器仅获得0!
错误:0
编号:1->物品名称=西瓜评估中...开始下载...
不幸的是,由于某些图像无法下载,因此无法全部下载4个图像。搜索过滤器仅获得0!
错误:0
实际上,这将创建一个文件夹,但其中没有图像。