Created
June 2, 2015 14:34
-
-
Save satetsu888/c4fd47b0d69c10203d9e to your computer and use it in GitHub Desktop.
amatenの価格調べ
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
require 'nokogiri' | |
require 'open-uri' | |
base_url = 'https://amaten.jp/exhibitions/past_gifts?page=%s&type=amazon' | |
last_line = 0; | |
current_line = 0; | |
page = 1; | |
loop do | |
url = sprintf(base_url, page) | |
charset = nil | |
html = open(url) do |f| | |
charset = f.charset | |
f.read | |
end | |
doc = Nokogiri::HTML.parse(html, nil, charset) | |
table = doc.css('table#gift_list') | |
table.css('tr.odd').each{|line| | |
datatime = line.css('td.cellLimit') | |
price = line.css('td.cellPrice') | |
rate = line.css('td.cellRate') | |
print datatime.text + ", " + rate.text + "\n" | |
current_line+=1 | |
} | |
page+=1 | |
if current_line == last_line then | |
break | |
else | |
last_line = current_line | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment