Ruby 初心者スレッド Part 21
■ このスレッドは過去ログ倉庫に格納されています
0022デフォルトの名無しさん
2008/08/08(金) 10:12:41module 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 http://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
とか書けるのって便利っぽくね?
WWW::Mechanizeライブラリがアップデートして中身が大幅工事されたとき涙目だけど
■ このスレッドは過去ログ倉庫に格納されています