以前のエントリで、RubyのNokogiriライブラリを使ったスクレイピングのやり方を紹介しました。 RubyのNokogiriを使ってサイトをスクレイピングする しかし、前回の方法では$ ruby scrape.rb http://eiga.com/movie/55975/ という様に一つひとつURLを指定しなければならず不便です。 そこで今回は前回のコードを拡張し、スクレイピングの自動化に挑戦します。 考え方 「自動化」というと難しい気がしますが、スクレイピングするURL(http://eiga.com/movie/55975/)の内、映画のidにあたる55975の部分を順に変化させていくことを今回のゴールとします。 ステップとしては2つで、 前回のコードを拡張し、存在しないURLへのアクセス時のエラー対応を実装 1のコードを別スクリプトから呼び出す という流れになるかと思います。 1