title: Pulling Yahoo Finance data using PYTHON
body: <p>I am using the following program to pull data from yahoo finance into a text file on the local drive.  The program does successfully pull the data from yahoo finance into a txt file in my computer.  </p>
  
  <p>Why do the code come up with 19 "error"'s followed by a successful pull? </p>
  
  <p>If I want to save the data to database server, how should I approach?</p>
  
  <pre><code>import urllib.request
  import time
  
  stockstoPull = 'AMD', 'BAC', 'MSFT', 'TXN', 'GOOG'
  
  def pullData(stock):
      fileLine = stock + '.txt'
      urltovisit = 'http://chartapi.finance.yahoo.com/instrument/1.0/'+stock+'/chartdata;type=quote;range=1y/csv'
  with urllib.request.urlopen(urltovisit) as f:
      sourceCode = f.read(100000).decode('utf-8')
  splitSource = sourceCode.split('\n')
  
  for eachLine in splitSource:
      splitLine = eachLine.split('.')
      if len(splitLine) == 5:
          if 'values' not in eachLine:
              saveFile = open(fileLine,'a')
              linetoWrite = eachLine+'\n'
              saveFile.write(linetoWrite)
      else:
          print('Error')
  
  print('Pulled', stock)
  print('...')
  time.sleep(.5)
  
  for eachStock in stockstoPull:     
      pullData(eachStock)
  </code></pre>