Created
November 19, 2010 12:03
-
-
Save malditogeek/706433 to your computer and use it in GitHub Desktop.
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' | |
require 'pp' | |
# User provided Book Depository wishlist. | |
wishlist_url = 'http://www.bookdepository.com/wishlist/507838/Mauro-Pompilio' | |
# Fectch the wishlisted books. | |
def fetch_books(wishlist_url, page=1) | |
doc = Nokogiri::HTML(open("#{wishlist_url}/?page=#{page}")) | |
doc.xpath('//div[@class="tabModules"]/ul/li/div[@class="module bookSmall"]/a') | |
end | |
# Go through every page until there are no more wishlisted books. | |
page = 0 | |
wishlist = [] | |
begin | |
books = fetch_books(wishlist_url, page += 1) | |
books.each do |book| | |
wishlist << {:title => book.xpath('img/@alt').first.value, | |
:cover => book.xpath('img/@src').first.value.gsub(/small/, 'medium'), | |
:title => book.attributes['href'].value} | |
end | |
end until books.empty? | |
pp wishlist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment