require "Nokogiri" | |
require "httparty" | |
class Scraper | |
@@shoes = [] | |
page = HTTParty.get("https://www.nike.com/w/mens-nike-by-you-lifestyle-shoes-13jrmz6ealhznik1zy7ok") | |
@parse_page ||= Nokogiri::HTML(page) | |
@parse_page.css('div.product-card__info').each do |char_element| | |
title = char_element.css("div.product-card__title").text.gsub(/\n/, "") | |
subtitle = char_element.css("div.product-card__subtitle").text.gsub(/\n/, "") | |
price = char_element.css("div.product-price").text.gsub(/\n/, "") | |
shoe_details = [title, subtitle, price] | |
@@shoes << shoe_details if !@@shoes.include?(shoe_details) | |
end | |
CSV.open('data.csv', "w+") do |csv| | |
@@shoes.each { |element| csv.puts(element) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment