Skip to content

Instantly share code, notes, and snippets.

@chrisroos
Created October 3, 2014 11:14
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 chrisroos/7094aa5a176ad18b52bc to your computer and use it in GitHub Desktop.
Save chrisroos/7094aa5a176ad18b52bc to your computer and use it in GitHub Desktop.
Parse CloudStore results and display as markdown

About

Parse a CloudStore search results page and display the results as markdown.

NOTE. It only displays the first page of search results

Usage example

$ curl -s "http://govstore.service.gov.uk/cloudstore/search/?q=software+development" | \
  ruby cloudstore-results-parser.rb
require 'nokogiri'
html = STDIN.read
doc = Nokogiri::HTML(html)
products = []
doc.search('.product-shop').each do |product|
name = product.search('.product-name').first.text.strip
price = product.search('.price').first.text.strip
url = product.search('.product-name a').first['href']
products << {name: name, price: price, url: url}
end
products.sort_by { |product| product[:name] }.each do |product|
puts "* [#{product[:name]}](#{product[:url]}) - #{product[:price]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment