简体   繁体   English

用python下载谷歌图片无法下载图片

[英]Google image download with python cannot download images

I'm using google_images_download library to download top 20 images for a keyword.我正在使用google_images_download库下载关键字的前 20 张图片。 It's worked perfectly when I'm using it last days.当我最后几天使用它时,它工作得很好。 Code is as follows.代码如下。

from google_images_download import google_images_download

response = google_images_download.googleimagesdownload()

arguments = {"keywords":keyword,"limit":10,"print_urls":True}
paths = response.download(arguments)

Now it gives following error.现在它给出了以下错误。

Evaluating...
Starting Download...


Unfortunately all 10 could not be downloaded because some images were not downloadable. 0 is all we got for this search filter!

Errors: 0

How can I solve this error.我该如何解决这个错误。

There has been some changes on Google end (how they respond to the request) which results in this issue.谷歌端发生了一些变化(他们如何响应请求)导致了这个问题。 Joeclinton1 on github has done some modifications to the original repo which provides a temporary fix. github 上的Joeclinton1对原始 repo 做了一些修改,提供了一个临时修复。

You can find the updated repo here: https://github.com/Joeclinton1/google-images-download.git .您可以在此处找到更新的存储库: https : //github.com/Joeclinton1/google-images-download.git The solution is in patch-1 branch if I'm not mistaken.如果我没记错的话,解决方案是在patch-1分支中。

  1. First uninstall the current version of google_images_download.首先卸载当前版本的 google_images_download。

  2. Then manually install Joeclinton1's repo by:然后通过以下方式手动安装 Joeclinton1 的 repo:

git clone https://github.com/Joeclinton1/google-images-download.git
cd google-images-download && sudo python setup.py install #no need for 'sudo' on windows Anaconda environment

or to install it with pip或者用pip安装

pip install git+https://github.com/Joeclinton1/google-images-download.git

This should solve the problem.这应该可以解决问题。 Note that currently this repo only supports upto 100 images.请注意,目前此 repo 最多仅支持 100 个图像。

I faced the same issue with google-image-download, which used to work perfect earlier!我在使用 google-image-download 时遇到了同样的问题,它以前可以完美运行! I have an alternative that I would like to suggest, which should solve the problem.我有一个我想建议的替代方案,它应该可以解决问题。

Solution: Instead of using google-image-download for Python, use bing-image-downloader, that downloads from Bing!解决方案:不要为 Python 使用 google-image-download,而是使用从 Bing 下载的 bing-image-downloader! search engine.搜索引擎。

Steps:脚步:

Step 1: Install the library by using: pip install bing-image-downloader第 1 步:使用以下命令安装库: pip install bing-image-downloader

Step 2:第2步:

from bing_image_downloader import downloader
downloader.download(query_string, limit=100,  output_dir='dataset', 
adult_filter_off=True, force_replace=False, timeout=60)

That's it!而已! All you would need to do is to add your image topic to the query_string.您需要做的就是将图像主题添加到 query_string。

Note:笔记:

Parameters that you can further tweak:您可以进一步调整的参数:

query_string : String to be searched. query_string :要搜索的字符串。

limit : (optional, default is 100) Number of images to download.限制:(可选,默认为 100)要下载的图像数量。

output_dir : (optional, default is 'dataset') Name of output dir. output_dir :(可选,默认为“数据集”)输出目录的名称。

adult_filter_off : (optional, default is True) Enable of disable adult filteration. Adult_filter_off :(可选,默认为 True)启用禁用成人过滤。

force_replace : (optional, default is False) Delete folder if present and start a fresh download. force_replace :(可选,默认为 False)删除文件夹(如果存在)并开始新的下载。

timeout : (optional, default is 60) timeout for connection in seconds. timeout : (可选,默认为 60) 连接超时秒数。

Further Reference: https://pypi.org/project/bing-image-downloader/进一步参考: https : //pypi.org/project/bing-image-downloader/

Another easy way to download any number of images :-另一种下载任意数量图像的简单方法:-

pip install simple_image_download pip 安装 simple_image_download

from simple_image_download import simple_image_download as simp从 simple_image_download 导入 simple_image_download 作为 simp

response = simp.simple_image_download response().download(a, b) response = simp.simple_image_download response().download(a, b)

Where a= string of subject you want to download B= number of images you want to download其中 a= 要下载的主题字符串 B= 要下载的图像数量

If you want to download less than 100 images per query string, google-images-download will work better than bing-images-downloader .如果您想为每个查询字符串下载少于 100 张图片, google-images-download会比bing-images-downloader更好。 It handles the errors better and, you know, Google Images gives quite better results than Bing equivalent.它可以更好地处理错误,而且,您知道,Google 图片提供的结果比 Bing 等价物要好得多。

However, if you're trying to download more than 100 images, google-images-downloader will give you a lot of headaches.但是,如果您尝试下载超过 100 张图片, google-images-downloader会让您头疼。 As mentioned in this answer , Google changed their end, and because of this the repo is having a lot of failures (more info on the situation statushere ).正如在这个答案中提到的,谷歌改变了他们的结局,因此回购有很多失败(关于情况状态的更多信息在这里)。

So, if you want to download thousands of images, use bing-image-downloader :因此,如果您想下载数千张图片,请使用bing-image-downloader

Install package from pip从 pip 安装包

pip install bing-image-downloader

Run query.运行查询。

NOTE: The documentation seems to be incorrect, as it returns a "No module found" error when importing the package as from bing_image_downloader import downloader (as mentioned in this answer ).注意:文档似乎不正确,因为它在from bing_image_downloader import downloader导入包时返回“未找到模块”错误(如本答案所述)。 Import it and use it like this:导入它并像这样使用它:

from bing_image_downloader.downloader import download

query_string = 'muscle cars'

download(query_string, limit=1000,  output_dir='dataset', adult_filter_off=True, force_replace=False, timeout=60, verbose=True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM