×
[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") } } } } |
require 'rubygems' require 'twitter' require 'nkf' #idとpasswordを入力 TWITTER_ID ='id' TWITTER_PASSWORD='passward' #メッセージを作成 message = NKF.nkf("-w","hello,world!") #twitterに投稿 twitter = Twitter::Base.new(TWITTER_ID,TWITTER_PASSWORD) twitter.update(message)
|
require 'rubygems' require 'hpricot' require 'open-uri' require 'net/http' Net::HTTP.version_1_2 links_list = [] n = 1 #画像のuriを収集 for i in 0..50 begin doc = Hpricot(open(uri = "http://doragong.19.dtiblog.com/page-#{i}.html").read.downcase) rescue sleep(1) retry end (doc/:a).each {|link| if link[:href] =~ /\.jpe?g/ links_list << link[:href] end } end #画像をダウンロードして保存 links_list.uniq!.each{|link| if link =~ %r|http://(.*?)(/.*/(.*\.jpg))| print n,"\sDownloding...\s",link,"\n" begin open($3,"wb"){|file| Net::HTTP.start($1, 80) {|http| response = http.get($2) file.puts response.body } } rescue next end n += 1 end } |