Created
May 2, 2012 05:38
-
-
Save reinforce-lab/2574159 to your computer and use it in GitHub Desktop.
kickstarter logger, backers/pledged
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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