我正在尝试找到一种高效且可复制的方法批量下载Google图像搜索中的全尺寸图像文件。其他人也问过类似的问题,但我没有找到完全符合我要求或我能理解的内容。
大多数参考了已弃用的Google Image Search API或Google Custom Search API,这似乎对整个网络都不起作用,或者仅关于从单个URL下载图像。
我想这可能是一个两步骤的过程:首先从搜索中提取所有图像URL,然后批量从这些URL下载?
我应该补充说明我是初学者(这可能很明显;抱歉)。因此,如果有人能够解释并指引我正确的方向,那将不胜感激。
我还研究了免费软件选项,但这些软件似乎也不稳定。除非有人知道一个可靠的软件。 从Google图像搜索下载图片(Python)
大多数参考了已弃用的Google Image Search API或Google Custom Search API,这似乎对整个网络都不起作用,或者仅关于从单个URL下载图像。
我想这可能是一个两步骤的过程:首先从搜索中提取所有图像URL,然后批量从这些URL下载?
我应该补充说明我是初学者(这可能很明显;抱歉)。因此,如果有人能够解释并指引我正确的方向,那将不胜感激。
我还研究了免费软件选项,但这些软件似乎也不稳定。除非有人知道一个可靠的软件。 从Google图像搜索下载图片(Python)
在Python中,我能否从**谷歌图片**搜索结果中下载所有/一些图像文件(例如JPG / PNG)?
如果有人了解这些标签的任何信息,并且它们是否存在于某个地方/与图像相关联? https://en.wikipedia.org/wiki/Google_Image_Labeler
import json
import os
import time
import requests
from PIL import Image
from StringIO import StringIO
from requests.exceptions import ConnectionError
def go(query, path):
"""Download full size images from Google image search.
Don't print or republish images without permission.
I used this to train a learning algorithm.
"""
BASE_URL = 'https://ajax.googleapis.com/ajax/services/search/images?'\
'v=1.0&q=' + query + '&start=%d'
BASE_PATH = os.path.join(path, query)
if not os.path.exists(BASE_PATH):
os.makedirs(BASE_PATH)
start = 0 # Google's start query string parameter for pagination.
while start < 60: # Google will only return a max of 56 results.
r = requests.get(BASE_URL % start)
for image_info in json.loads(r.text)['responseData']['results']:
url = image_info['unescapedUrl']
try:
image_r = requests.get(url)
except ConnectionError, e:
print 'could not download %s' % url
continue
# Remove file-system path characters from name.
title = image_info['titleNoFormatting'].replace('/', '').replace('\\', '')
file = open(os.path.join(BASE_PATH, '%s.jpg') % title, 'w')
try:
Image.open(StringIO(image_r.content)).save(file, 'JPEG')
except IOError, e:
# Throw away some gifs...blegh.
print 'could not save %s' % url
continue
finally:
file.close()
print start
start += 4 # 4 images per page.
# Be nice to Google and they'll be nice back :)
time.sleep(1.5)
# Example use
go('landscape', 'myDirectory')
更新
我能够按照这里指定的方式创建一个使用完整网络的自定义搜索,并成功执行以获取图像链接,但正如在之前的帖子中提到的那样,它们并不完全与正常的Google图像结果对齐。