Skip to content

Instantly share code, notes, and snippets.

@fractalatcarf
Created January 16, 2018 16:46
Show Gist options
  • Save fractalatcarf/a2f4848c16335bb912372c264e71fce1 to your computer and use it in GitHub Desktop.
Save fractalatcarf/a2f4848c16335bb912372c264e71fce1 to your computer and use it in GitHub Desktop.
sarenza live code
require 'open-uri'
require 'nokogiri'
require 'json'
url = "http://www.sarenza.com/store/product/gender-luxe/list/view?gender=1&luxe=1&index=0&count=2000"
html_file = open(url).read
html_doc = Nokogiri::HTML(html_file)
scrap = []
html_doc.search('.vignette').each do |element|
brand = element.search('.brand').text.strip
model = element.search('.model').text.strip
price = element.search('.price').text.strip.gsub(",",".").to_f
scrap << {brand: brand, model: model, price: price}
end
File.open("sarenza.json", 'wb') do |file|
file.write(JSON.pretty_generate(scrap))
end
puts "#{scrap.length} elements scrapped !"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment