你好,我有这个代码,但得到这些错误
主循环“tuple”对象没有属性“read”和 主循环模块“urllib”没有属性“urlopen”
def pullData(stock):
try:
fileLine = stock+'.txt'
urlToVisit = 'http://chartapi.finance.yahoo.com/instrument/1.0/'+stock+'/chartdata;type=quote;range=10d/csv'
sourceCode = urllib.urlopen(urlToVisit).read()
splitSource = sourceCode.split('\n')
for eachLine in splitSource:
splitLine = eachLine.split(',')
if len(splitLine)==6:
if 'values' not in eachLine:
saveFile = open(fileLine,'a')
lineToWrite = eachLine+'\n'
saveFile.write(lineToWrite)
print('Pulled',stock)
print('sleeping')
time.sleep(5)
except Exception as e:
print('main loop',str(e))
pullData(stockToPull)
在Python 3中,} 中,因此可以执行以下操作:
urlopen()
位于^{对于剩下的代码,最好使用一个HTML解析器,比如BeautifulSoup或{a3}。在
相关问题 更多 >
编程相关推荐