LoginSignup
2

More than 5 years have passed since last update.

画像のスクレイピング

Last updated at Posted at 2017-01-15

Googleカスタムサーチを使う方法

Google Custom Search APIの有効化と、サーチエンジンの作成を事前にします。その上で、.bash_profile や .bashrcに以下を記述

export GOOGLE_API_KEY=
export GOOGLE_SEARCH_ENGINE=

imageGetter(){curl "https://www.googleapis.com/customsearch/v1?key=$GOOGLE_API_KEY&cx=$GOOGLE_SEARCH_ENGINE&searchType=image&q=$1" | grep 'jpg\|png' | sed -e "s/\"link\": //g" | sed -e "s/\"//g" | sed -e "s/\,//g" | xargs wget -P $2;}

以下の様に使います。

imageGetter cat tmpdir

catの検索結果がtmpdirに格納されます。

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
2