Ruby Script to parse ISBNs listed in R-Project to populate an Amazon

June 7, 2010
By

(This article was first published on R-Chart, and kindly contributed to R-bloggers)

As you probably figured out, I am an Amazon affiliate and have been giving some thought to how to get the best lists of R books available at Amazon. To get the list of ISBNs from R-Project, the following Ruby script did the trick:

require 'rubygems'
require 'open-uri'
require 'hpricot'

isbns=[]

doc=Hpricot(open('http://www.r-project.org/doc/bib/R-books.html'))

(doc/'td[@class^="bibtexitem"]').each{|entry|
entry.inner_text.split("\n").each{|l|isbns << l=~/ISBN/}
}

isbns.map!{|i|
['.', ':', '-', 'ISBN',', in German',', in Czech'].each{|e|
i.gsub!(e,'')
}

i.strip!
}

isbns.delete_if{|x|x.nil?}

puts isbns.join('|')

The pipe-delimited list could then be supplied in this Amazon Search Page. If you are interested in seeing the result, click here.


To leave a comment for the author, please follow the link and comment on his blog: R-Chart.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags:

Comments are closed.