Created
April 4, 2014 11:39
-
-
Save geeknees/9972792 to your computer and use it in GitHub Desktop.
amazon_scrape.rb
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
# coding: utf-8 | |
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
require 'colored' | |
# KINDLE CHECK SCRIPT | |
# | |
# ruby -U amazon_scrape.rb [put url here] | |
# | |
# FOR EXAMPLE | |
# ruby -U amazon_scrape.rb http://www.amazon.co.jp/registry/wishlist/1HZANEXEX7OZ3 | |
# | |
wishlist_url = ARGV.first | |
doc = Nokogiri::HTML(open(wishlist_url)) | |
last_page = doc.css('span.pagPage').last.text | |
puts "Getting from ... #{wishlist_url}\n".red.underline | |
(1..last_page.to_i).each do |page| | |
doc = Nokogiri::HTML(open("#{wishlist_url}?page=#{page}")) | |
doc.css('span.productTitle a').each do |el| | |
doc = Nokogiri::HTML(open(el["href"])) | |
unless doc.css('div.fionaPublish').empty? && doc.css('tbody#kindle_meta_binding_winner').empty? | |
puts "Title".blue | |
puts doc.css('span#btAsinTitle').first.content | |
unless doc.css('tbody#kindle_meta_binding_winner').empty? | |
puts "Kindle URL".blue | |
if doc.css('tbody#kindle_meta_binding_winner a').empty? | |
puts el["href"] | |
else | |
puts doc.css('tbody#kindle_meta_binding_winner a').first["href"] | |
end | |
end | |
unless doc.css('div.fionaPublish').empty? | |
puts "Kindle化リクエスト".blue | |
puts "http://www.amazon.co.jp#{doc.css('div.fionaPublish a').first["href"]}" | |
end | |
puts "\n" | |
end | |
sleep 1 | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment