Skip to content

Instantly share code, notes, and snippets.

@maddox
Created November 7, 2019 22:14
Show Gist options
  • Save maddox/1346b0a4bc6eb7bd4605614ba99861b4 to your computer and use it in GitHub Desktop.
Save maddox/1346b0a4bc6eb7bd4605614ba99861b4 to your computer and use it in GitHub Desktop.
Best Buy Price Checker
require 'rubygems'
require 'nokogiri'
require 'open-uri'
products = []
products << ["Beverage Cooler", "https://www.bestbuy.com/site/insignia-115-can-beverage-cooler-black-stainless-steel/6027001.p?skuId=6027001"]
products << ["10TB drive", "https://www.bestbuy.com/site/wd-easystore-10tb-external-usb-3-0-hard-drive-black/6278208.p?skuId=6278208"]
products << ["Hue White 4 pack", "https://www.bestbuy.com/site/philips-hue-white-a19-bluetooth-smart-led-bulb-4-pack-white/6347040.p?skuId=6347040"]
def get_price(url)
doc = Nokogiri::HTML(open(url))
doc.css('div > div > div.pricing-lib-price-7-1943-5.price-view-pb.priceView-layout-large > div > div:nth-child(2) > div > div > div > span:nth-child(1)').first.content
end
products.each do |product|
puts "#{product[0]}: #{get_price(product[1])}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment