Advertisement
Guest User

Untitled

a guest
Oct 14th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. import bs4
  2. import requests
  3.  
  4. def stockprice():
  5.     stock = raw_input('Which stock price would you like?: ' )
  6.     res = requests.get('http://finance.yahoo.com/q?s=' + stock)
  7.        
  8.     soup = bs4.BeautifulSoup(res.text, 'html.parser')
  9.     #elems looks up current stock price, adding ticker
  10.     elems = soup.select('#yfs_l84_'+stock)
  11.     price = elems[0].text.strip()
  12.     return "The current stock price of "+stock+" is "+price
  13.    
  14. print stockprice()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement