为什么不能';我不能用python从谷歌下载图像吗?
代码帮助我从谷歌下载了一堆图片。几天前它还可以工作,现在代码突然中断了 代码:为什么不能';我不能用python从谷歌下载图像吗?,python,python-3.x,google-image-search,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',
# 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
这实际上创建了一个文件夹,但其中没有图像。看起来包有问题。看看这些开放的PRs:and我认为谷歌正在改变DOM。元素class=“rg_meta notranslate”不再存在。它更改为class=“rg_i…”
# 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()
事实上,这个问题不久前就出现了,现在已经有很多类似的Github问题:
不幸的是,目前还没有正式的解决方案,您可以使用讨论中提供的临时解决方案。这不起作用的原因是谷歌改变了他们做任何事情的方式,因此您现在需要搜索字符串中包含的api_键。因此,即使您使用2.8.0版本,google images download等软件包也不再有效,因为它们没有用于插入api_密钥字符串的占位符,您必须向google注册才能获得每天2500次的免费下载 如果您愿意每月支付50美元或以上从访问服务,一种方法是使用pip包
谷歌搜索结果
,并提供api_密钥作为查询参数的一部分
params = {
"engine" : "google",
...
"api_key" : "secret_api_key"
}
您自己提供API密钥,然后调用:
client = GoogleSearchResults(params)
results = client.get_dict()
这将返回一个JSON字符串,其中包含指向所有图像URL的链接,然后您可以直接下载它们。google\u images\u download项目似乎不再兼容wrt google api
你也可以试试。我不明白为什么这篇文章有两个不喜欢的地方?我也有同样的问题。几天前它还可以正常工作。很久以前访问过它们,但仍然无法解决问题。那么,如何更改它们?从哪里获得API密钥?。你必须提供谷歌和信用卡的登录详细信息,但你每天可以下载25000个项目而不必付费。我正在使用它,但我今天也听说他有自己的谷歌图片下载代码变体,允许你每天下载100张图片。