Skip to content

Instantly share code, notes, and snippets.

@kitz99
Created June 29, 2018 05:53
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 kitz99/16ac2fddbee8a6cce58a6771768d6fce to your computer and use it in GitHub Desktop.
Save kitz99/16ac2fddbee8a6cce58a6771768d6fce to your computer and use it in GitHub Desktop.
results = []
products = document.xpath("//ul[@class='products']/li")
products.each do |p|
json_product = {}
json_product[:title] = p.xpath("div/div[@class='product-header']").text.strip
json_product[:description] = p.xpath("div/div[@class='product-body']/p[contains(@class, 'description')]").text.strip
json_product[:price] = p.xpath("div/div[@class='product-footer']/p[contains(@class, 'price')]").text.strip
results << json_product
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment