A Beer Atom Feed
So, after reviewing over 50 beers on BeerAdvocate, I’ve come to the conclusion that them not having an RSS or Atom feed of my most recent reviews available is stupid. So, I decided to make my own by scraping their HTML today. I started off by pumping some random code into irb that included Hpricot and Builder. Ruby rocks for doing stuff like this.
So, after reviewing over 50 beers on BeerAdvocate, I’ve come to the conclusion that them not having an RSS or Atom feed of my most recent reviews available is stupid. So, I decided to make my own by scraping their HTML today. I started off by pumping some random code into irb that included Hpricot and Builder. Ruby rocks for doing stuff like this. Anyway, I ended up with this at the end:
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'builder'
# Get the document to scrape
doc = Hpricot(open("http://beeradvocate.com/user/beer_reviews?user=ralree"))
trs = (doc/"table")[2].search("tr")
# Create the feed
target = File.new("beer.xml", "w")
xml = Builder::XmlMarkup.new(:target => target, :indent => 1)
xml.instruct!
xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
xml.id "http://www.ralree.info/beer.xml"
xml.title "ralree the BeerAdvocate"
xml.subtitle "Recent Beer Reviews"
xml.link "rel" => "self", "href" => "http://www.ralree.info/beer.xml"
xml.updated Time.now.iso8601
xml.author { xml.name "Erik Gregg"; xml.email "ralree@gmail.com" }
# For each TR, make an entry
trs.each do |a|
tds = a.search("td").to_a
if tds.length == 7
xml.entry do
xml.updated(Time.parse(tds[0].inner_html.gsub('-', '/')).iso8601)
xml.title((tds[1]/"a/b").inner_html)
xml.link(:href =>
("http://www.beeradvocate.com" + ((tds[1]/"a")[0]["href"]))) do |x|
xml.text!((tds[1]/"a/b")[0].inner_html)
end
xml.summary do |p|
p.cdata! <<EOOMFG
Brewery: #{(tds[2]/"a")[0].inner_html}
Style: #{(tds[3]/"a")[0].inner_html}
Serving: #{tds[4].inner_html}
ABV: #{tds[5].inner_html}
Rating: #{(tds[6]/"b").inner_html}
EOOMFG
end
end
end
end
end
This produces the feed that you can find here. Feel free to add it to your aggregator, and you’ll be notified whenever I review a beer! This is what it looks like:

Get the codez here
