Created
January 16, 2018 16:46
-
-
Save fractalatcarf/a2f4848c16335bb912372c264e71fce1 to your computer and use it in GitHub Desktop.
sarenza live code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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