Skip to content

Instantly share code, notes, and snippets.

@munk
Forked from CloudCray/scrape_stock.py
Last active August 29, 2015 14:10
Show Gist options
  • Save munk/2a718991c6662f23fdf4 to your computer and use it in GitHub Desktop.
Save munk/2a718991c6662f23fdf4 to your computer and use it in GitHub Desktop.
# Python 3.4
import requests
import bs4
def get_stock_price(name):
url = "https://www.google.com/finance"
data = requests.get(url, params={'q': name})
bs = bs4.BeautifulSoup(data.text)
div_price = bs.find(attrs={"id": "price-panel"})
span_price = div_price.find(attrs={"class": "pr"})
return float(span_price.text.strip())
print(get_stock_price("GOOG"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment