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

[This article was first published on R-Chart, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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(‘https://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 their blog: R-Chart.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)