Advertisement
ellesehc

Sentdex code

Mar 17th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. import time #library1 dunno why he called this library, for accuracy of the ratio perhaps?
  2. import urllib2 #library2 of course I need this, but what does it actually do??
  3.  
  4. from urllib2 import urlopen #will look up actual effect
  5. sp500short = ['a', 'aa', 'aapl', 'abbv', 'abc', 'abt', 'ace', 'aci', 'acn', 'act', 'adbe', 'adi', 'adm', 'adp'] #sample stock names
  6. def yahooKeyStats(stock): #function for yahoo finance info grabber
  7.         try: #will look search for this in pydocs and see other examples for clarity
  8.                 sourceCode = urllib2.urlopen('http://finance.yahoo.com/q/ks?s='+stock).read() #analyze/review
  9.                 pbr = sourceCode.split('Price/Book (mrq):</td><td class="yfnc_tabledata1">')[1].split('</td>')[0] #You kinda get this, hone this one
  10.                 print 'price to book ratio:',pbr #output of Price to Book ratio
  11.  
  12.         except Exception, e: #except and Exception?? I have no idea! Will research!
  13.                 print 'failed in the main loop',str(e) #wtf is e? where did that come from??
  14.  
  15.                
  16. yahooKeyStats('aapl')
  17. price to book ratio: 6.00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement