rubyでblogを自動投稿する・・ってのを見つけた
rubyでblogを自動投稿するスクリプトを書いてみた | earth ってページを見つけたんで、早速コピペで動かしてみたけど・・・ダメだった。
いろいろとググってみて、「mixiのページはeuc-jpでMechanizeがうまくいかないのでid:otn:20090429の細工。」っていう記述を見つけた。livedoorもeucなんで・・ってことで、以下を参考にWWW::Mechanizeを拡張してた。
スクレイピングのためのNokogiri利用メモ - それはそれ。これはこれ。
require "rubygems" require "mechanize" require "kconv" class WWW::Mechanize def set_hook @post_connect_hook.hooks << Proc.new do |params| params[:response_body] = NKF.nkf("-wm0",params[:response_body]) params[:response]["Content-Type"]="text/html; charset=utf-8" end end end agent = WWW::Mechanize.new agent.set_hook agent.user_agent_alias = "Windows IE 7"
これで、ログインするとこまではできた。