Skip to content

Instantly share code, notes, and snippets.

@reinforce-lab
Created May 2, 2012 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reinforce-lab/2574159 to your computer and use it in GitHub Desktop.
Save reinforce-lab/2574159 to your computer and use it in GitHub Desktop.
kickstarter logger, backers/pledged
$KCODE = "UTF8"
require 'rubygems'
require 'nokogiri'
require 'open-uri'
#ターゲットのURLと、ファイル名
target_url = "http://www.kickstarter.com/projects/rowdyrobot/tod-connect-real-world-actions-to-mobile-devices-a"
target_file ="tod.csv"
interval = 3600
loop do
#スクレイピング
page = open(target_url)
html = Nokogiri::HTML(page.read, nil, 'UTF-8')
node = html.xpath('//div[attribute::class="num"]/text()')
#CSV1行テキストを作る
s = Time.now.strftime("%Y-%m-%d %H:%M:%S")
s<<","
node.each_with_index do |a, i|
s << a
s << ","
end
s <<"¥n"
#ファイル書き出し
f = File::open(target_file, "a")
f.write(s)
f.close
#puts s
#次まで待ち
sleep interval
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment