Created
October 10, 2017 13:04
-
-
Save pkbanks/86f008bb9f96fd7c56c4f0c926db8eb3 to your computer and use it in GitHub Desktop.
stock price scraper from google finance, keyed off stock symbol
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 'httparty' | |
require 'nokogiri' | |
tickers = [ | |
'FB', | |
'GOOGL' | |
] | |
prices = [] | |
def get_price(ticker) | |
h = Hash.new | |
url = "https://finance.google.com/finance" | |
q_string = "?q=#{ticker}" | |
response = HTTParty.get(url + q_string) | |
parsed = Nokogiri::HTML(response.body) | |
price = parsed.css('span.pr').text.to_f | |
puts "#{ticker} @ #{price}" | |
h[ticker] = price | |
return h | |
end | |
for stock_symbol in tickers | |
prices << get_price(stock_symbol) | |
end | |
p prices |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment