1
2

More than 1 year has passed since last update.

google-images-download使い方メモ

Posted at

準備

google-images-downloadをインストール

この時pipでやらずに公開されているGithubからcloneします。

コマンドプロンプト
git clone https://github.com/Joeclinton1/google-images-download.git gid-joeclinton

この時最新版のseleniumがダウンロードされるが、find_element_byから始まるメソッドが使えなくなっているので、バージョンを落とす必要があるため一度seleniumを削除して、古いバージョンを入れる。

コマンドプロンプト
pip uninstall selenium
コマンドプロンプト
pip install selenium==4.0.0

seleniumのバージョンが4.3.0より古ければ大丈夫だと思う。

Chrome Driverのインストール

Downloads – ChromeDriverからChromeDriverをダウンロード。
zipファイルを展開して実行するPythonファイルと同じディレクトリに入れておく。

Pythonファイル

Pythonの実行ファイルはこんな感じ。

#モジュールのインポート
from google_images_download import google_images_download  
#responseオブジェクトの生成
response = google_images_download.googleimagesdownload()  

#検索キーワード/ダウンロード画像の数

arguments = {"keywords":検索したいワード,
              "limit":1000,
              "chromedriver":"chromedriver.exe",
              "format":"jpg"
             } 

#ダウンロードの実行
response.download(arguments)

keywordsに検索するワードを入れる。スペースを使うのはあり。
limitは何枚の画像を保存するのかを指定する。今回の場合は1000枚ダウンロードしてる。
chromedriverはさっきダウンロードしたchromedriverのpath
formatは保存形式を指定する。

実行すると実行したディレクトリにdownloadsという名前のフォルダが作成されてその中にダウンロードした画像が保存される。

参考

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2