hpricotが1.9でうごいて一安心
#hpricotでOK require 'hpricot' require 'open-uri' require 'kconv' doc = Hpricot(open("http://youtubeanisoku1.blog106.fc2.com/").read ) top_info = (doc/"div.Top_info") next_links = [] (top_info/:a).each do |link| #"更新状況"を持ってるか否か if /更新状況/ =~ link.inner_html.toutf8 #linkはnext_linkに溜め込んでおく next_links << link[:href] end end #最新の更新情報にアクセセス。要するに今日 doc = Hpricot(open(next_links[0]).read ) #articleのaからyoutube.anisokuのモノをフィルター article_info = doc/"div.article" article_a = article_info/:a contents_info = [] article_a.each do |link| if /youtubeanisoku/ =~ link[:href] contents_info << link[:href] end end puts "個別ページまでいった" #contents_infoを対象にデータを取りに行く #threadで加速すると503くらいます。ぐ。。 #threads =[] contents_info.each do |target| # threads << Thread.new do # begin doc = Hpricot(open(target).read ) #kijisubに動画へのリンクが仕込まれてる article_info = doc/"div.kijisub" article_a = article_info/:a #記事のa要素リスト格納 #今回はlinkだけを出力ではなくarrayに突っコム(後でreverseして出力する) article_a.select do |link| /comeid=/ =~ link[:href] end.reverse.each do |e| puts e end # rescue => ex # puts ex # end #end end
eachと=~で回すよりもselect/collectを使う方が
かっこよい気もしていたけれど、読みやすさでは一歩後退、かな。
ともかく普通に動いてよかたー。