Skip to content

Instantly share code, notes, and snippets.

@saasindustries
Created January 25, 2021 13:05
Show Gist options
  • Save saasindustries/c028d823db1cf207ca85cbc9557271b2 to your computer and use it in GitHub Desktop.
Save saasindustries/c028d823db1cf207ca85cbc9557271b2 to your computer and use it in GitHub Desktop.
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