Ruby の scrAPI使ってて嵌った。
ニコニコ動画(RC2)の発表中ずっと止まってたのかよNice boat.じゃね?っていうか、げんしけんのWebラジオあげたうp主、タイトルが確信犯的に分かりづらくね?分かったよアニメイトTV WEBの方見てくるよ、あえてRuby の scrAPI使ってな!
まあ、もっと良い方法とかそれplaとかあるんだろうけど、ソースもドキュメントも読んでないから分かるはずも無いわ。
$ vi test-scrapi.rb
require 'rubygems' require 'scrapi' require 'open-uri' require 'nkf' $KCODE = 'u' atw_url = "http://www.animate.tv/digital/web_radio/detail_114.html" ex1 = Scraper.define do #process 'tr:first-child > td:nth-child(6) > a[href]', "urls[]" => "@href" process 'title', :title => :text process 'td.main_txt2', "dates[]" => :text process 'table[width="553"] > tr:nth-child(1) > td.main_txt1 > strong', "subtitles[]" => :text result :title, :dates, :subtitles end ex2 = Scraper.define do #process 'tr:first-child > td:nth-child(6) > a[href]', "urls[]" => "@href" process 'title', :title => :text process 'td.main_txt2', "dates[]" => :text process 'table[width="553"] > tbody > tr:nth-child(1) > td.main_txt1 > strong', "subtitles[]" => :text #result :title, :dates, :subtitles, :urls result :title, :dates, :subtitles end html = NKF::nkf('-w m0', open(atw_url).read) struct1 = ex1.scrape(html, :parser_options => {:char_encoding=>'utf8'}) p title1 = struct1[:title] p dates1 = struct1[:dates] p subtitles1 = struct1[:subtitles] struct2 = ex2.scrape(html, :parser_options => {:char_encoding=>'utf8'}) p title2 = struct2[:title] p dates2 = struct2[:dates] p subtitles2 = struct2[:subtitles]
で、〜〜2の方が正しいと思っていたのに〜〜1の方じゃないと取れない。
$ ruby test-scrapi.rb "アニメイトTV WEB -『げんしけん2』Webラジオ げんちょけん(現代聴覚文化研究会)-" ["2007年10月9日放送"] ["第0回 【げんちょうけん?】"] "アニメイトTV WEB -『げんしけん2』Webラジオ げんちょけん(現代聴覚文化研究会)-" ["2007年10月9日放送"] nil
nilて。gaxtu
tbodyって認識されないもんなの?っていうかアニメイトTV WEBのHTMLって(ry
参考:
http://d.hatena.ne.jp/secondlife/20060922/1158923779
川o・-・)<2nd life - ruby のスクレイピングツールキット scrAPI
http://wota.jp/ac/?date=20070115#p05
ヽ( ・∀・)ノくまくまー(2007-01-15)
http://blog.labnotes.org/2006/07/11/scraping-with-style-scrapi-toolkit-for-ruby/
Labnotes » Scraping with style: scrAPI toolkit for Ruby
http://labnotes.org/svn/public/ruby/scrapi/cheat/scrapi.html
scrAPI Cheat Sheet
http://www.animate.tv/digital/web_radio/detail_114.html
アニメイトTV WEB -『げんしけん2』Webラジオ げんちょけん(現代聴覚文化研究会)-
http://www.animate.tv/digital/web_radio/detail_104.html
アニメイトTV WEB -Webラジオ-さよなら絶望放送-