×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
require "open-uri" require "date" require "nkf" today = Date.today last_day = Date.new(1999,1,1) exchange_type = ["usdjpy","audjpy","gbpjpy","cadjpy","chfjpy","eurjpy"] exchange_type.each{|k| open("#{k}.csv","w"){|file| 0.step(today - last_day,50){|i| url = open("http://table.yahoo.co.jp/t?s=#{k}=x&a=#{last_day.month}&b=#{last_day.day}&c=#{last_day.year}&d=#{today.month}&e=#{today.day}&f=#{today.year}&g=d&q=t&y=#{i}&z=#{k}=x&x=.csv") text = url.read text_sjis = NKF.nkf("-s",text) text_sjis.scan(/<small>(\d*)年(\d*)月(\d*)日<\/small>< \/td>.<td><small>([\d\.]*)<\/small><\/td>.<td><small>([\d\.]*)<\/small><\/td>.<td><small>([\d\.]*)<\/small><\/td>.<td><small>([\d\.]*)<\/small>/m){|matched| file.print(matched[0],"/",matched[1],"/",matched[2],",",matched[3],",",matched[4],",",matched[5],",",matched[6],"\n") } } } } |