お世話になります。duta と申します。
Mechanize で 巨大なファイル 27Mbyte をダウンロードする以下のようなスクリプトを書きましたが、Timeoutしてしまいます。
どのような設定をとれば回避できるのか、おわかりになる方がおりましたらお教え願いたくメールいたしました。
よろしくお願いします。
require 'rubygems'
require 'mechanize'
require 'kconv'
#=============
def link_edge(link)
page = link.click
page.links.each do |link|
if link.text =~ /PH/
#さらにジャンプ
form_submit(link)
end
end
end
#=======================================================
# フォームに値をセットしてサブミットする。
#======================================================
def form_submit(link)
puts " click "+link.text
page = link.click
#puts page.body
page.forms.name('ptselect').radiobuttons.name('pt').value='s' # radio button 選択
page.forms.name('ptselect').fields.name('syear').value='2007' # radio button 選択
page.forms.name('ptselect').fields.name('smon').value='6'
page.forms.name('ptselect').fields.name('sday').value='1'
page.forms.name('ptselect').fields.name('shour').value='0'
page.forms.name('ptselect').fields.name('smin').value='0'
page.forms.name('ptselect').fields.name('int').value='366' # radio button 選択
#page.forms.name('ptselect').fields.name('int').value='7' # radio button 選択
result = page.forms.name('ptselect').submit
link_dump(result,link.text)
end
#==========================
# 検索結果をファイルに出力
#==========================
def link_dump(page,name)
# puts result.body
page.links.each do |link|
if link.text =~ /CS/
#さらにジャンプ
page = link.click
page.max_history=0
page.open_timeout(nil)
page.read_timeout(nil)
page.keep_alive_time(3600)
wf = File.new("./core_edge/"+name+".txt", "w")
wf.print page.body
wf.close
#puts nam
#puts page.body
end
end
end
#--------- main program --------------
agent = WWW::Mechanize.new # インスタンス生成
agent.auth('admin','admin')
page = agent.get('http://hogehoge/cgi-bin/grapher/') # ページ取得
page.links.each do |link|
#puts link.text.tosjis
if link.text =~ /([0-9A-Za-z]+)-dc-RM/
#マッチしたので移動
link_edge(link)
end
end
表示されるエラー
c:/rails/ruby/lib/ruby/1.8/timeout.rb:54:in `rbuf_fill': execution expired (Time
out::Error)
from c:/rails/ruby/lib/ruby/1.8/timeout.rb:56:in `timeout'
from c:/rails/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout'
from c:/rails/ruby/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
from c:/rails/ruby/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
from c:/rails/ruby/lib/ruby/1.8/net/protocol.rb:126:in `readline'
from c:/rails/ruby/lib/ruby/1.8/net/http.rb:2236:in `read_chunked'
from c:/rails/ruby/lib/ruby/1.8/net/http.rb:2216:in `read_body_0'
from c:/rails/ruby/lib/ruby/1.8/net/http.rb:2182:in `read_body'
... 14 levels...
from gri_gra1_get.rb:16:in `link_edge'
from gri_gra1_get.rb:82
from gri_gra1_get.rb:78:in `each'
from gri_gra1_get.rb:78
_________________________________________________________________
10M 1★480円!Hotmailユーザー限定のブロードバンドサービス
http://campaign.live.jp/eaccess/Top/