Skip to content

Instantly share code, notes, and snippets.

@chrisroos chrisroos/README.md
Created Oct 3, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.