Skip to content

BingやGoogleのAPIを叩いて画像収集するやつ

License

Notifications You must be signed in to change notification settings

ysdyt/image_collectors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image_collectors

画像検索APIを叩いて画像収集するやつです(スクレイピングではなく、正規の手順でAPIを叩きます)
BingとGoogleそれぞれのパターンがありますので、所属する宗教の方をお使いください。救われさえすればいいという無宗教の方はBingを強くおすすめします。

スクレイピングではなくAPIを使うため課金が発生しますが、アカウント設立時に貰える無料クーポンで実質無料みたいなもんです(クーポン利用期間制限はありますが)

それぞれの詳細は以下もご参照ください

実行環境

  • Python3

実行方法

API keyの設定

Bing or GoogleのAPI keyを事前に取得している前提です。
API keyは実行スクリプトとは別のファイルauthentication.iniに書き込み、configparseで読み出す形式になっています。

まず、bing_image_collector.pyなどがあるのと同じ階層でauthentication.iniファイルを作成します。

$ touch authentication.ini

作成したauthentication.iniに取得したAPI keyを以下のように書き込みます。BingとGoogleで必要なkeyだけ書けば大丈夫です(両方は必要ありません)。

[auth]
bing_api_key = xxxxxxxxxxxxxxxx
google_api_key = xxxxxxxxxxxxxxxxx
google_se_key = xxxxxxxxxxxxx

(注意!)文字列はシングルコートなどで囲わずそのまま書き込む

  • bing_api_key ・・・ Bing Image Search APIのkeyを指定します。API keyの取得方法の例はこちら
  • google_api_key ・・・ Google Custom Search APIのkeyを指定します。API keyの取得方法の例はこちら
  • google_se_key ・・・ Google Custom Engineのkeyを指定します。Google Custom Search APIを利用するには Search API用のkeyの他に、Custom Engineのkeyも必須となります。取得例はこちら

スクリプトの実行

Bing Image Search APIを利用する場合

$ python3 bing_image_collector.py

検索クエリーやパラメータなどの指定方法はQiitaにまとめました

Google Custom Search APIを利用する場合

$ python3 google_image_collector.py

検索クエリーやパラメータなどの指定方法はQiitaにまとめました

About

BingやGoogleのAPIを叩いて画像収集するやつ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages