Skip to content

Instantly share code, notes, and snippets.

@jwoertink
Created July 6, 2020 17:10
Show Gist options
  • Save jwoertink/bdd170a296b54280ea77949f82638ac0 to your computer and use it in GitHub Desktop.
Save jwoertink/bdd170a296b54280ea77949f82638ac0 to your computer and use it in GitHub Desktop.
require 'httparty'
require 'nokogiri'
class Scraper
attr_accessor :parse_page
def initialize
doc = HTTParty.get("http://store.nike.com/us/en_us/pw/mens-nikeid-lifestyle-shoes/1k9Z7puZoneZoi3")
@parse_page ||= Nokogiri::HTML(doc)
end
def get_names
names = item_container.css(".product-name").css("p").children.map { |name| name.text }.compact
end
def get_prices
price = item_container.css(".product-price").css("span-local").children.map { |price| price.text }.compact
end
private
def item_container
parse_page.css(".grid-item-info")
end
- scraper = Scraper.new
- prices = scraper.get_prices
- names = scraper.get_names
- (0...prices.size).each do |index|
- puts "- - - index: #{index + 1} - - - "
- puts " Name: #{names [index]} Price: #{prices[index]}"
- end
end
+ scraper = Scraper.new
+ prices = scraper.get_prices
+ names = scraper.get_names
+ (0...prices.size).each do |index|
+ puts "- - - index: #{index + 1} - - - "
+ puts " Name: #{names [index]} Price: #{prices[index]}"
+ end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment