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