当我尝试从整个标准普尔 500 指数创建 CSV 文件时收到此错误消息:
Exception has occurred: pandas_datareader._utils.RemoteDataError
Run Code Online (Sandbox Code Playgroud)
没有使用 YahooDailyReader 获取符号 3M 公司的数据
我认为这是有问题的:
for row in table.findAll('tr') [1:]:
ticker = row.findAll('td')[0:].text
Run Code Online (Sandbox Code Playgroud)
有人能帮帮我吗?提前致谢。
完整代码-
import bs4 as bs
import datetime as dt
import os
import pandas_datareader.data as web
import pickle
import requests
def save_sp500_tickers():
resp = requests.get('http://en.wikipedia.org/wiki/List_of_S%26P_500_companies')
soup = bs.BeautifulSoup(resp.text, 'lxml')
table = soup.find('table', {'class': 'wikitable sortable'})
tickers = []
for row in table.findAll('tr') [1:]:
ticker = row.findAll('td')[0:].text
tickers.append(ticker)
with open("sp500tickers.pickle", "wb") as f:
pickle.dump(tickers, f)
return tickers
# …Run Code Online (Sandbox Code Playgroud)