Ich benutze Python v3.6. Für ein Youtube-Tutorial folge ich. Aus irgendeinem Grund, wenn ich diesen Code ausführen, sehe ich CSV-Datei gespeichert wurde (genau 47 Dateien), aber nicht alle von ihnen. Kann mir bitte jemand zeigen, was ich falsch mache.Fehler Web Scraping Daten von Yahoo
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
from matplotlib.finance import candlestick_ohlc
import matplotlib.dates as mdates
import pandas as pd
import pandas_datareader.data as web
import bs4 as bs
import pickle
import requests
import os
import csv
import numpy as np
def tsx_tickers():
resp = requests.get('http://web.tmxmoney.com/indices.php?section=tsx&index=%5ETSX')
soup = bs.BeautifulSoup(resp.text, "lxml")
table = soup.find('table', {'class': 'indices-table'})
tickers = []
for row in table.findAll('tr')[1:]:
ticker = row.findAll('td')[1].text
tickers.append(ticker.replace(".","-") + ".TO")
with open("tsxticker.pickle", "wb") as f:
pickle.dump(tickers, f)
print(tickers)
return tickers
def get_data_from_yahoo(reload_tsx = False):
if reload_tsx:
tickers = tsx_tickers()
else:
with open("tsxticker.pickle", "rb") as f:
tickers = pickle.load(f)
if not os.path.exists('stock_dfs'):
os.makedirs('stock_dfs')
start = dt.datetime(2000, 1, 1)
end = dt.datetime(2016, 12, 13)
for ticker in tickers:
if not os.path.exists('stock_dfs/{}.csv'.format(ticker)):
time.sleep(2)
df = web.DataReader(ticker, 'yahoo', start, end)
df.to_csv('stock_dfs/{}.csv'.format(ticker))
else:
print('Already have {}'.format(ticker))
Ich erhalte diesen Fehler
Traceback (most recent call last):
File "C:\Users\X\Desktop\xfile\sentdex.py", line 77, in <module>
get_data_from_yahoo()
File "C:\Users\X\Desktop\xfile\sentdex.py", line 72, in get_data_from_yahoo
df = web.DataReader(ticker, 'yahoo', start, end)
File "C:\Users\X\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\data.py", line 116, in DataReader
session=session).read()
File "C:\Users\X\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\yahoo\daily.py", line 76, in read
df = super(YahooDailyReader, self).read()
File "C:\Users\X\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\base.py", line 155, in read
df = self._read_one_data(self.url, params=self._get_params(self.symbols))
File "C:\Users\X\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\base.py", line 74, in _read_one_data
out = self._read_url_as_StringIO(url, params=params)
File "C:\Users\X\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\base.py", line 85, in _read_url_as_StringIO
response = self._get_response(url, params=params)
File "C:\Users\X\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas_datareader\base.py", line 120, in _get_response
raise RemoteDataError('Unable to read URL: {0}'.format(url))
pandas_datareader._utils.RemoteDataError: Unable to read URL: http://ichart.finance.yahoo.com/table.csv?s=OTEX.TO&a=0&b=1&c=2015&d=11&e=13&f=2016&g=d&ignore=.csv