Skip to content

Instantly share code, notes, and snippets.

@allolex
Created July 15, 2015 16:23
Show Gist options
  • Select an option

  • Save allolex/dbd6194f6495473fb5c5 to your computer and use it in GitHub Desktop.

Select an option

Save allolex/dbd6194f6495473fb5c5 to your computer and use it in GitHub Desktop.
require "httparty"
require "nokogiri"
stock_code = ARGV[0]
url = "http://finance.yahoo.com/q?s=#{stock_code}"
response = HTTParty.get url
dom = Nokogiri::HTML(response.body)
name = dom.xpath('//*[@id="yfi_rt_quote_summary"]/div[1]/div/h2').first.content
stock_price = dom.xpath("//*[@id=\"yfs_l84_#{stock_code.downcase}\"]").first.content
prev_price = dom.xpath('//*[@class="yfnc_tabledata1"]').first.content
ask_price = dom.xpath('//*[@class="yfnc_tabledata1"]')[3].content
puts "#{name}'s stock is at #{stock_price}, but it was #{prev_price}."
puts "Asking: #{ask_price}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment