Skip to content

Instantly share code, notes, and snippets.

@kelsos
Created May 23, 2015 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelsos/4975512d266d540ce2cc to your computer and use it in GitHub Desktop.
Save kelsos/4975512d266d540ce2cc to your computer and use it in GitHub Desktop.
Parser for the quote html page.
require 'nokogiri'
require 'rubygems'
require 'json'
page = Nokogiri::HTML(open("quotes.htm"))
quotes = page.css(".quote")
all_quotes = []
quotes.each do |quote|
id = quote.attribute("id").text.gsub! "quote", ""
id = id.to_i
header = quote.css('h2')
title = header.text
header.remove
submitted_tag = quote.css('.submitted')
submitted = submitted_tag.text
submitted_tag.remove
current_quote = {
:title => title,
:id => id,
:submitted => submitted,
:message => quote.text
}
all_quotes.push(current_quote)
end
File.write('quote.json', all_quotes.to_json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment