memo.log

技術情報の雑なメモ

映画ログの自分の棚の中身をスクレイピングしておく

映画ログがサービス終了するとのこと。データのエクスポートには対応しないとのことなので、自力でラックの映画タイトル一覧を取得するスクリプトを準備した。

www.eiga-log.com

まず、自分のラックページで、Chromeデベロッパーツールを開き、以下を実行。

var arr = [];
elements = document.querySelectorAll(".bookreviewList_title");
elements.forEach(function(element){
  arr.push(element.children[0].href);
});
console.log(arr);

各映画の詳細URLのリストを取得できるので、以下Rubyスクリプトでタイトルを抽出。

require "open-uri"
require "nokogiri"

urls = %w(
...
)

urls.each do |url|
  html = URI.open(url).read
  doc = Nokogiri::HTML.parse(html)
  pp doc.css("h1").children[0].children.to_s
end