Trying to pull stock data from Yahoo Finance using Python 3.5 -


hello have code getting these errors

main loop 'tuple' object has no attribute 'read' , main loop module 'urllib' has no attribute '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')          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 e:         print('main loop',str(e))  pulldata(stocktopull) 

in python 3, urlopen() in urllib.request, can this:

from urllib.request import urlopen  sourcecode = urlopen(urltovisit).read() 

regarding rest of code might better off using html parser such beautifulsoup or lxml.html.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -