当我运行代码时,我收到错误“主循环失败类型str不支持缓冲区API”:
import time
import urllib
from urllib.request import urlopen
sp500short = ['a', 'aa', 'aapl', 'abbv', 'abc', 'abt', 'ace', 'aci', 'acn', 'act', 'adbe', 'adi', 'adm']
def yahooKeyStats(stock):
try:
sourceCode = urlopen('http://www.advfn.com/stock-market/NYSE/'+stock+'/financials').read()
pbr = sourceCode.split("Price/Book Ratio</td><td class='s' align='right'>")[1].split("</td>")[0]
print ("Price to book ratio:",pbr)
except Exception,e:
print ("Failed in the main loop", str(e))
for eachStock in sp500short:
yahooKeyStats(eachStock)