>>21 module Hatena class Mechanize < WWW::Mechanize attr_accessor :username, :password LOGIN_URI = URI.parse('https://www.hatena.ne.jp/login') def login orig_get(LOGIN_URI).forms[0].set_fields('name' => @username, 'password' => @password) submit(page.forms[0]) end alias orig_get get def get(uri,param=[],ref=nil) login if cookie_jar.empty?(LOGIN_URI) _get(uri,param,ref) end
class ConfigPage < ::WWW::Mechanize::Page # is for d.hatena.ne.jp/+username+/config def counter @counter ||= parser.search('div.note').find{|e| /#{'ページビュー'.toeuc}/e =~ e.inner_text}.inner_text.scan(/\d+/).to_s.to_i end end end