簡體   English   中英

用python下載谷歌圖片無法下載圖片

[英]Google image download with python cannot download images

我正在使用google_images_download庫下載關鍵字的前 20 張圖片。 當我最后幾天使用它時,它工作得很好。 代碼如下。

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)

現在它給出了以下錯誤。

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

我該如何解決這個錯誤。

谷歌端發生了一些變化(他們如何響應請求)導致了這個問題。 github 上的Joeclinton1對原始 repo 做了一些修改,提供了一個臨時修復。

您可以在此處找到更新的存儲庫: https : //github.com/Joeclinton1/google-images-download.git 如果我沒記錯的話,解決方案是在patch-1分支中。

  1. 首先卸載當前版本的 google_images_download。

  2. 然后通過以下方式手動安裝 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

或者用pip安裝

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

這應該可以解決問題。 請注意,目前此 repo 最多僅支持 100 個圖像。

我在使用 google-image-download 時遇到了同樣的問題,它以前可以完美運行! 我有一個我想建議的替代方案,它應該可以解決問題。

解決方案:不要為 Python 使用 google-image-download,而是使用從 Bing 下載的 bing-image-downloader! 搜索引擎。

腳步:

第 1 步:使用以下命令安裝庫: pip install bing-image-downloader

第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)

而已! 您需要做的就是將圖像主題添加到 query_string。

筆記:

您可以進一步調整的參數:

query_string :要搜索的字符串。

限制:(可選,默認為 100)要下載的圖像數量。

output_dir :(可選,默認為“數據集”)輸出目錄的名稱。

Adult_filter_off :(可選,默認為 True)啟用禁用成人過濾。

force_replace :(可選,默認為 False)刪除文件夾(如果存在)並開始新的下載。

timeout : (可選,默認為 60) 連接超時秒數。

進一步參考: https : //pypi.org/project/bing-image-downloader/

另一種下載任意數量圖像的簡單方法:-

pip 安裝 simple_image_download

從 simple_image_download 導入 simple_image_download 作為 simp

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

其中 a= 要下載的主題字符串 B= 要下載的圖像數量

如果您想為每個查詢字符串下載少於 100 張圖片, google-images-download會比bing-images-downloader更好。 它可以更好地處理錯誤,而且,您知道,Google 圖片提供的結果比 Bing 等價物要好得多。

但是,如果您嘗試下載超過 100 張圖片, google-images-downloader會讓您頭疼。 正如在這個答案中提到的,谷歌改變了他們的結局,因此回購有很多失敗(關於情況狀態的更多信息在這里)。

因此,如果您想下載數千張圖片,請使用bing-image-downloader

從 pip 安裝包

pip install bing-image-downloader

運行查詢。

注意:文檔似乎不正確,因為它在from bing_image_downloader import downloader導入包時返回“未找到模塊”錯誤(如本答案所述)。 導入它並像這樣使用它:

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